datareader in asp.net using c#
-
Hi All, Can anybody help me?.... I am using a datareader to read from the database, i have the select query for this & reading the contents of the table ok... I am getting the correct output using a datareader for the datagrid ....as.... DGShow.DataSource=dread; DGShow.DataBind(); ...but i want to put the same contains in the textbox also....but whenever i read the contains i am getting this error message.... Exception Details: System.InvalidOperationException: Invalid attempt to read when no data is present. the code is...... while(dread.Read()) { txtEmpID.Text=dread.GetString(0); txtEmpName.Text =dread.GetString(1); txtcity.Text=dread.GetString(2); txtphone.Text=dread.GetInt32(3); } as i am not sure that i m on right track please help me.. thanks
-
Hi All, Can anybody help me?.... I am using a datareader to read from the database, i have the select query for this & reading the contents of the table ok... I am getting the correct output using a datareader for the datagrid ....as.... DGShow.DataSource=dread; DGShow.DataBind(); ...but i want to put the same contains in the textbox also....but whenever i read the contains i am getting this error message.... Exception Details: System.InvalidOperationException: Invalid attempt to read when no data is present. the code is...... while(dread.Read()) { txtEmpID.Text=dread.GetString(0); txtEmpName.Text =dread.GetString(1); txtcity.Text=dread.GetString(2); txtphone.Text=dread.GetInt32(3); } as i am not sure that i m on right track please help me.. thanks
Hi, Once the datareader is assigned to the DGShow(datagrid) as a datasource.you cannot use the same datareader for assiging in textboxs. For this you need close the datareader and again open it and for assigning to textboxs. i will give the code below. DGShow.DataSource=dread; DGShow.DataBind(); dread.close(); dread=cmd.ExecuteReader(); //ExecuteReader method on Command Object. while(dread.Read()) { txtEmpID.Text=dread.GetString(0); txtEmpName.Text =dread.GetString(1); txtcity.Text=dread.GetString(2); txtphone.Text=dread.GetInt32(3); } Regards, Sukesh.g Sukesh.g
-
Hi, Once the datareader is assigned to the DGShow(datagrid) as a datasource.you cannot use the same datareader for assiging in textboxs. For this you need close the datareader and again open it and for assigning to textboxs. i will give the code below. DGShow.DataSource=dread; DGShow.DataBind(); dread.close(); dread=cmd.ExecuteReader(); //ExecuteReader method on Command Object. while(dread.Read()) { txtEmpID.Text=dread.GetString(0); txtEmpName.Text =dread.GetString(1); txtcity.Text=dread.GetString(2); txtphone.Text=dread.GetInt32(3); } Regards, Sukesh.g Sukesh.g
Hi, In the following code the last line.... dread=cmd.ExecuteReader(); //ExecuteReader method on Command Object. while(dread.Read()) { txtEmpID.Text=dread.GetString(0); txtEmpName.Text =dread.GetString(1); txtcity.Text=dread.GetString(2); txtphone.Text=dread.GetInt32(3); //****giving error**** } ....is giving error like ////// {specified cast is not valid} as in sql database Phone field is numeric.....if i change it's datatype to decimal & that line to this.... txtphone.Text=dread.GetDecimal(3).ToString(); then it works.....so plz help me if i ve numeric or int. datatype of fields in the database...then how to read them??....which GetXXXXX() function, we will use for that... please help me... Thanks
-
Hi, In the following code the last line.... dread=cmd.ExecuteReader(); //ExecuteReader method on Command Object. while(dread.Read()) { txtEmpID.Text=dread.GetString(0); txtEmpName.Text =dread.GetString(1); txtcity.Text=dread.GetString(2); txtphone.Text=dread.GetInt32(3); //****giving error**** } ....is giving error like ////// {specified cast is not valid} as in sql database Phone field is numeric.....if i change it's datatype to decimal & that line to this.... txtphone.Text=dread.GetDecimal(3).ToString(); then it works.....so plz help me if i ve numeric or int. datatype of fields in the database...then how to read them??....which GetXXXXX() function, we will use for that... please help me... Thanks