T
Thushan Withanage
Guest
i have a database table in sql server 2017. when i retrieve a record from sqldatareader it is possible to store that value in a string variable. But i cannot use it outside the dr.Read() function. i want to display resulting the value in the txt3 text box.
con = new SqlConnection("Data Source=DESKTOP-GSJITB6\\MICROSOFT;Initial Catalog=AuditLog;Integrated Security=True");
con.Open();
cmd = new SqlCommand("Select top 1 id,prefix from Customer2 order by id desc", con);
dr = cmd.ExecuteReader();
while(dr.Read())
{
string a = dr.GetInt32(0).ToString();
string b = dr.GetString(1);
}
txt3.Text = (a + b);
dr.Close();
con.Close();
Continue reading...
con = new SqlConnection("Data Source=DESKTOP-GSJITB6\\MICROSOFT;Initial Catalog=AuditLog;Integrated Security=True");
con.Open();
cmd = new SqlCommand("Select top 1 id,prefix from Customer2 order by id desc", con);
dr = cmd.ExecuteReader();
while(dr.Read())
{
string a = dr.GetInt32(0).ToString();
string b = dr.GetString(1);
}
txt3.Text = (a + b);
dr.Close();
con.Close();
Continue reading...