1

I want to add ASP.NET code-behind C# Dropdownlist selected value to the SQL Server database. I'm using a stored procedure and in SQL Server it works when I execute the procedure.

I have added database connection (dal.class) file to the VS project.

My code in dal.class is

 public void SaveDelData(int pkg_no, int pkg_cat_id, String reference_no, String sender, String receiver_name, String receiver_address, int area_id, int city_id, int zone_id, String date, String telephone, bool isDelete)
 {
            try
            {
                SqlCommand cmdGetItem = new SqlCommand();
                cmdGetItem.Connection = con;
                cmdGetItem.CommandText = "SavedeliveryData"; 
                cmdGetItem.CommandType = CommandType.StoredProcedure;

                cmdGetItem.Parameters.AddWithValue("@pkg_no", pkg_no);
                cmdGetItem.Parameters.AddWithValue("@pkg_cat_id", pkg_cat_id);
                cmdGetItem.Parameters.AddWithValue("@sender", sender);
                cmdGetItem.Parameters.AddWithValue("@receiver_name", receiver_name);
                cmdGetItem.Parameters.AddWithValue("@receiver_address", receiver_address);
                cmdGetItem.Parameters.AddWithValue("@area_id", area_id);
                cmdGetItem.Parameters.AddWithValue("@city_id", city_id);
                cmdGetItem.Parameters.AddWithValue("@zone_id", zone_id);
                cmdGetItem.Parameters.AddWithValue("@date", date);
                cmdGetItem.Parameters.AddWithValue("@telephone", telephone);
                cmdGetItem.Parameters.AddWithValue("@isDelete", isDelete);

                con.Open();
                cmdGetItem.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
            }
            finally
            {
                con.Close();
            }
        }

and I have 4 dropdownlists on the design page which get data from the other table for particular data.

my C# code is

dataAccess data = new dataAccess();

        int pkg_id; 
        if (packageid.Text == string.Empty || packageid.Text == "")
            pkg_id = -1;
        else
            pkg_id = Int32.Parse(packageid.Text);

        string sData1 = this.category.SelectedValue;
        string sData2 = this.area.SelectedValue;
        string sData3 = this.city.SelectedValue;
        string sData4 = this.zone.SelectedValue;

     // string cat = category.SelectedItem.Value.ToString();
     // string areaa = area.SelectedItem.Value.ToString();
     //string cityy = city.SelectedItem.Value.ToString();
     // string zonee = zone.SelectedItem.Value.ToString();

        data.SaveDelData(pkg_id, sData1, sender_name.Text, receivername.Text, receiver_address.Text, sData2,sData3,sData4, date.Text, telephone.Text, false);

I want to send send dropdownlist selected item to the database but it give the error in

data.SaveDelData(pkg_id, sData1, sender_name.Text, receivername.Text, receiver_address.Text, sData2,sData3,sData4, date.Text, telephone.Text, false);

as

No overload for method 'SaveDelData' takes 11 arguments

How can I fix this one ?

Thanks in advance :)

3
  • Doesn't any of the answers help ? Commented Nov 26, 2013 at 6:07
  • got it , now the problem is get the selected values to the database :D Commented Nov 26, 2013 at 7:11
  • edit question and explain again in detail, what is the problem, where it is coming Commented Nov 26, 2013 at 7:18

3 Answers 3

1
 public void SaveDelData(int pkg_no, int pkg_cat_id, String reference_no, String sender, String receiver_name, String receiver_address, int area_id, int city_id, int zone_id, String date, String telephone, bool isDelete)
    {


     }

Obviously you can count 12 parameters in the above function

so you are missing one and i guess its pkg_cat_id

data.SaveDelData(pkg_id,(integer type parameter here 'pkg_cat_id'), sData1, sender_name.Text, receivername.Text, receiver_address.Text, sData2,sData3,sData4, date.Text, telephone.Text, false);
Sign up to request clarification or add additional context in comments.

Comments

1

Change your call to 'SaveDelData' method and give it 12 arguments. You are only passing 11! I think you are missing the pkg_cat_id?

3 Comments

Hi thanks for your reply geedubb , Can you explain more about the answer ? , where i should change it ?
Check your data.SaveDelData call. It only has 11 args
think you are missing the pkg_cat_id
0

As per following function definition you need to pass 12 parameters while making a call.

public void SaveDelData(int pkg_no, int pkg_cat_id, String reference_no, String sender, String receiver_name, String receiver_address, int area_id, int city_id, int zone_id, String date, String telephone, bool isDelete)

In the following call you are passing only 11 parameters.

data.SaveDelData(pkg_id, sData1, sender_name.Text, receivername.Text, receiver_address.Text, sData2,sData3,sData4, date.Text, telephone.Text, false);

In above call first parameter is package Id, second is selected category and the third is the name of the sender. But as per function definition third parameter should be a string reference Id. So I think you missed to pass that reference id. Add it in your parameter list and it work fine.

Regards,

Nitin Joshi

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.