Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Apr 26, 2011, 4:53 AM EDT
You need SQL query or VB.Net code to retrive userid & passwd.?
From where you need to retrive?
soniya8 reputationPosted Apr 26, 2011, 5:05 AM EDT
Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Apr 26, 2011, 9:18 PM EDT
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
Dea SaddlerRank #289 · 8.7K reputationPosted Apr 26, 2011, 10:17 PM EDT