How to retrive userid (Varchar) & passwd (Varchar) from odbc
How to retrive userid (Varchar) & passwd (Varchar) from odbc
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Dea SaddlerPosted Apr 27, 2011, 2:17 AM
Jaganathan BantheswaranPosted Apr 27, 2011, 1:18 AM
The C#code follows:
using System;
using Microsoft.Data.Odbc;
namespace BuilderODBC {
class TestClass {
static void Main(string[] args)
{
string connectionString ="DSN=Test;UID=username;Pwd=password;";
string sql = "SELECT userid, passwd FROM LoginTable";
OdbcConnection conn= new OdbcConnection(connectionString);
conn.Open();
OdbcCommand comm = new OdbcCommand(sql, conn);
OdbcDataReader dr = comm.ExecuteReader();
while (dr.Read())
{
Console.WriteLine("The user name is :" +dr.GetValue(0).ToString());
Console.WriteLine("The password is :" +dr.GetValue(1).ToString());
}
conn.Close();
dr.Close();
comm.Dispose();
conn.Dispose();
}
}
}
The equivalent VB .NET code follows:
Imports Microsoft.Data.Odbc
Module Module1
Sub Main()
Dim conn As OdbcConnection
Dim comm As OdbcCommand
Dim dr As OdbcDataReader
Dim connectionString As String
Dim sql As String
connectionString ="DSN=Test;UID=username;Pwd=password;"
sql = "SELECT userid, passwd FROM LoginTable"
conn = New OdbcConnection(connectionString)
conn.Open()
comm = New OdbcCommand(sql, conn)
dr = comm.ExecuteReader()
While (dr.Read())
Console.WriteLine("The user name is :" +dr.GetValue(0).ToString());
Console.WriteLine("The password is :" +dr.GetValue(1).ToString());
End While
conn.Close()
dr.Close()
comm.Dispose()
conn.Dispose()
End Sub
End Module
soniyaPosted Apr 26, 2011, 9:05 AM
Jaganathan BantheswaranPosted Apr 26, 2011, 8:53 AM
You need SQL query or VB.Net code to retrive userid & passwd.?
From where you need to retrive?