Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
public void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'timtableDataSet.sewagram' table. You can move, or remove it, as needed.
            this.sewagramTableAdapter.Fill(this.timtableDataSet.sewagram);
            con = new SqlConnection("server=ABHINAV-PC;database=timtable;trusted_connection=true");
            con.Open();
            ds = new DataSet();
        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            if (textBox3.Text == "Hutatma express")
            {
                SqlCommand cm2 = new SqlCommand("Select * from hutatma", con);
                dataGridView1.DataSource = cm2;
                cmd = new SqlCommand("select * from traintime", con);
                cmd1 = new SqlCommand("select * from traintime", con);
                trs();
            }
            else if (textBox3.Text == "Sewagram express")
            {
                SqlCommand cm1 = new SqlCommand("select * from sewagram", con);
                dataGridView1.DataSource = cm1;
                Image image1 = Image.FromFile(@"D:\asp.net practice\mindicator\mindicator\image\sevagram exp12.jpg");
                label3.Image = image1;
            }
Posted
Updated 25-Jan-14 18:33pm
v2

1 solution

You cannot assign a command object to a datagridview source.

Check this for your correction.

C#
private void button2_Click_1(object sender, EventArgs e)
        {
            if (textBox3.Text == "Hutatma express")
            {
                SqlCommand cm2 = new SqlCommand("Select * from hutatma", con);
                DataTable dth = new DataTable();
                SqlDataAdapter da = new SqlDataAdapter(cm2);
                da.Fill(dth);
                dataGridView1.DataSource = dth;
                cmd = new SqlCommand("select * from traintime", con);
                cmd1 = new SqlCommand("select * from traintime", con);
                trs();
            }
            else if (textBox3.Text == "Sewagram express")
            {
                SqlCommand cm1 = new SqlCommand("select * from sewagram", con);
                DataTable dts = new DataTable();
                SqlDataAdapter da = new SqlDataAdapter(cm2);
                da.Fill(dts);
                dataGridView1.DataSource = dts;
                Image image1 = Image.FromFile(@"D:\asp.net practice\mindicator\mindicator\image\sevagram exp12.jpg");
                label3.Image = image1;
 
Share this answer
 
Comments
Abhinav Chaudhary 26-Jan-14 6:24am    
Thanks a lot sir....!!!!Really thanks...It works...Thank You!
Karthik_Mahalingam 26-Jan-14 6:25am    
welcome :)
if it works, pls mark it as 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