Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hey my problem is that
i create a dropdown , a text box with ajax calender exdender and a passport with textbox and a search button and their is a database table applicant
when i am fill this three fields with select dropdown item that is binded and select date and fill passport then i click on search button my code is bellow(and i have also create a view where i convert date according to match their name is vw_ApplicantDetails and convert date column is v_ApplicationDate)VisaTypeNeeded_FK is foreign key
C#
string strSql = string.Empty;
       ddpl = visatype.SelectedItem.Value;
       strSql = "select * from vw_ApplicantDetails where AssignedTo = 'E' and     v_ApplicationDate='" + TextBox1.Text.ToString() + "' and Passport='" +  passport.Text.ToString() + "' and VisaTypeNeeded_FK='" +  visatype.SelectedItem.Value + "'";

       SqlCommand cmd = new SqlCommand(strSql);
       SqlDataAdapter adapter = new SqlDataAdapter(cmd);
       DataSet ds = new DataSet();
       adapter.Fill(ds, "Applicant");
       GridView1.DataSource = ds.Tables["Applicant"];
       GridView1.DataBind();

it show the error
Fill: SelectCommand.Connection property has not been initialized.

please anyone help me..
Posted
Updated 24-Jul-12 21:42pm
v2
Comments
Member 9208931 25-Jul-12 5:04am    
i have used this but it will show the same problem that
Fill: SelectCommand.Connection property has not been initialized.

1 solution

Where is your connection string?
C#
SqlConnection cn = new SqlConnection(YourConnectionString)

Try something like this:
C#
cn.open();//Open connection
SqlCommand cmd = new SqlCommand(strSql);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adapter.Fill(ds, "Applicant");
GridView1.DataSource = ds.Tables["Applicant"];
GridView1.DataBind();
cn.close()//close connection
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900