المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : retreiving values from datatable



C# Programming
09-20-2009, 05:52 PM
Hello.
I m using C# and sql server2005
I want to retrieve values from Datatable but dt kno how to do this.
My code is as follows,it checks from view(since it is the combination of specific columns from 2 tables)that whether the a particular service is reserved for the next day or not:



dtTableRecords_out = null;
string strQueryString = null;
SqlCommand objSqlCommand = null;
SqlConnection objSqlConnection = null;
DataSet objDataSet = null;
SqlDataAdapter objDataAdapter = null;
SqlDataReader objDataReader = null;
string day = (DateTime.Now.AddDays(1).Day.ToString());
string month = (DateTime.Now.Month.ToString());
string year = (DateTime.Now.Year.ToString());
string date_nextDay = month + '/' + day + '/' + year;

try
{
objDataSet = new DataSet();
objDataAdapter = new SqlDataAdapter();
objSqlConnection = new SqlConnection(ConnectionString.GetSQLConnectionString());
strQueryString = "select * from view_reservation where date = " + date_nextDay;
objSqlCommand = new SqlCommand(strQueryString, objSqlConnection);

objDataAdapter.SelectCommand = objSqlCommand;
objSqlConnection.Open();
objDataSet.Clear();

objDataAdapter.Fill(objDataSet);
objSqlConnection.Close();
dtTableRecords_out = objDataSet.Tables[0];

if (strQueryString != null)
{
Console.WriteLine("Service is reserved for tommorow");
}
else
{
Console.WriteLine("no reervation");

}

}

finally
{

if (objSqlConnection.State == ConnectionState.Open)
{
objSqlConnection.Close();
}

}
return strQueryString;
}


but the if statement is not executiong correctly.
I want the result(eg service_name or customer_id) from the query for further processing.

Hope that u ppl will provide me with an answer.I am sorry i forgot to put my code inside code block