SqlDataReader
rdr = null; SqlConnection con = null; SqlCommand cmd = null; string txtLastName = TextBox1.Text; try{
string ConnectionString = "server=DEL-CD212; uid=sa;" + "pwd=graver; database=Test;";con=
new SqlConnection(ConnectionString);con.Open();
string CommandText = "SELECT last_name, first_name" + "FROM try" + "WHERE last_name=;" + txtLastName;
cmd =
new SqlCommand(CommandText);cmd.Connection = con;
rdr = cmd.ExecuteReader();
while(rdr.Read()){
ListBox1.Items.Add(rdr[
"last_name"].ToString() + ", " + rdr["first_name"].ToString());}
}
catch(Exception ex){
ListBox1.Items.Add(ex.Message);
}
finally{
if(rdr !=null)rdr.Close();
if(con.State == ConnectionState.Open)con.Close();
}
Any help would be greatly appreciated.
MichellePosted Jun 21, 2007, 2:59 PM
Mahesh ChandPosted Jun 21, 2007, 2:32 PM
"SELECT last_name, first_name " + " FROM try WHERE last_name= ' " + txtLastName + " ' ";