Click here to Skip to main content
13,832,066 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have four DropDownList in Asp.Net. So I want to send values selected from the DropDownLists as four parameters to my stored procedure in Sql server and when I hit the Submit button, I want to get the data back from Sql Server to Asp.Net and publish it on a GridView. I have tried some codes. Since I am fairly new in Asp.Net, so I am not sure what is wrong with my code below.

What I have tried:

protected void Button1_Click1(object sender, EventArgs e)
    string s = "Submit";
    SqlCommand cmd = new SqlCommand(s, con);
    DataSet ds = new DataSet();
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.Add("@Address", SqlDbType.VarChar).Value = DropDownList5.SelectedItem.Value;
    cmd.Parameters.Add("@Number", SqlDbType.VarChar).Value = DropDownList2.SelectedItem.Value;
    cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = DropDownList3.SelectedItem.Value;
    cmd.Parameters.Add("@Type", SqlDbType.VarChar).Value = DropDownList4.SelectedItem.Value;
    GridView1.DataSource = ds;
Updated 19-Jun-18 6:55am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Replace your cmd.ExecuteNonQuery() by below and it should work. ExecuteNonQuery will execute the query but no data return instead it will return no of record affected and should be used to insert/delete/update statements only.

SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();

GridView1.DataSource = ds.Table[0];

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web05 | 2.8.190114.1 | Last Updated 19 Jun 2018
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100