Error in Asp.net c#,Grid view,Data set,

Posted by Raja_89 under C# on 3/19/2013 | Points: 10 | Views : 1354 | Status : [Member] | Replies : 2
Hai
When i select the values from drop down list the necessary details are showed
I have the following the code while it runs it displays the code:
SqlConnection objcon = new SqlConnection("Data Source=.;Initial Catalog=Iwens_Database;User ID=qwd;Password=123;Integrated Security=SSPI;");


SqlCommand objcom = new SqlCommand("SELECT * FROM dbo.Enquiry_table where DOEn >'" + FromTextBx.Text + "' AND DOEn<='" + ToTextBx.Text + "'", objcon);
SqlDataAdapter sda = new SqlDataAdapter();
// DataSet objds = new DataSet(); which is in command line
DataTable sdt = new DataTable();

sda.Fill(sdt );
BetweenGridView.DataSource = sdt;
BetweenGridView.DataBind();

The SelectCommand property has not been initialized before calling 'Fill'.




Responses

Posted by: Satyapriyanayak on: 3/19/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
SqlConnection objcon = new SqlConnection(strConnString);
objcon.Open();
SqlCommand objcom = new SqlCommand();
DataTable sdt = new DataTable();
objcom.Connection = objcon;
objcom.CommandText = "select * from dbo.Enquiry_table where DOEn>'" + TextBox1.Text.ToString() + "' and DOEn<'" + TextBox2.Text.ToString() + "'";
SqlDataAdapter sda = new SqlDataAdapter(objcom);
sda.Fill(sdt);
BetweenGridView.DataSource = sdt;
BetweenGridView.DataBind();
objcon.Close();

If this post helps you mark it as answer
Thanks

Raja_89, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Brahmam on: 3/19/2013 [Member] Starter | Points: 25

Up
0
Down
once check it this line

SqlDataAdapter sda = new SqlDataAdapter();

modfile this

sqlDataAdapter sda =new SqlDataAdapter(cmd);

Once check it

brahmam

Raja_89, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response