Visual Studio 2017

  • Thread starter Thread starter Thushan Withanage
  • Start date Start date
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...
 

Similar threads

M
Replies
0
Views
108
Meladl
M
T
Replies
0
Views
70
Thushan Withanage
T
T
Replies
0
Views
72
Thushan Withanage
T
Back
Top