How to pull one record and store value to a variable instead of a grid?
Posted on 2011-05-03
I'm using SQL 2005, with Visual Studio 2005/ASP 3.5. I'm trying to make my first Sql server connection, to store the values into a string variable. But unsuccessful. I'd appreciated if some one could tell me what I'm doing wrong or is there a better way. I'm use to just dumping the table into grid, but now I need it in a variable instead.
string sqlCheck = "SELECT lastrundate FROM CheckStatus WHERE sitename = 'Pack'";
string = "Data Source=169.00.00.1;Initial Catalog=DatabaseName;User Id=useridtest;Password=passwordtest";
// Establish SqlServer Connection
using (SqlConnection conn = new SqlConnection(connectionStr))
using (SqlDataAdapter a = new SqlDataAdapter(sqlCheck,conn))
DataTable t = new DataTable();
if (t.DataSet.Tables.Count > 0)
// How do I store the value from this one record into a variable?