Click to See Complete Forum and Search --> : Somebody help me


aneeshjohn
July 24th, 2006, 04:36 AM
hi...
i m using the DataReader statement :

SqlConnection cn = myConnect();
string query = "select e_id from employee where e_name = @name";
SqlDataReader dr = SqlHelper.ExecuteReader(cn,CommandType.Text,query,new SqlParameter("@name",TextBox1.Text.ToString()));
if(dr.HasRows)
{
TextBox2.Text = dr.GetInt16(0).ToString();



}
but it is giving me the error

Server Error in '/The DataList' Application.
--------------------------------------------------------------------------------

Specified cast is not valid.

jasonli
July 24th, 2006, 07:26 AM
At first, you should make sure that the query got data from DB. And then did you call dr.Read()?

Or something wrong with "GetInt16".