hi all

i make a store procdeure in visual studio wpf when i run a code the error is not solve

here is error
"Procedure getguestinfo has no parameters and arguments were supplied."

and here is the code

public class guests    
    {

        private int guest_id;

        public int Guest_id
        {
            get { return guest_id; }
            set { guest_id = value; }
        }
        private string first_name;

        public string First_name
        {
            get { return first_name; }
            set { first_name = value; }
        }
        private string last_name;

        public string Last_name
        {
            get { return last_name; }
            set { last_name = value; }
        }
        private string gender_status;

        public string Gender_status
        {
            get { return gender_status; }
            set { gender_status = value; }
        }
        private string martial_status;

        public string Martial_status
        {
            get { return martial_status; }
            set { martial_status = value; }
        }
        private int phone_numb;

        public int Phone_numb
        {
            get { return phone_numb; }
            set { phone_numb = value; }
        }
        private string email_id;

        public string Email_id
        {
            get { return email_id; }
            set { email_id = value; }
        }

        DataSet ds = new DataSet();





        public string displaydata()
        {


            string ConString = @"Data source = .\SqlExpress ; Database=htm ;Integrated security=true";

            SqlConnection con = new SqlConnection(ConString);
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = new SqlCommand("select * from guestinfo");
            da.Fill(ds);
            ds.Clear();
            return "done";
        }

        public void add()
        {
            guests gus = new guests();

            string ConString = @"Data Source=USER-PC\SQLEXPRESS;Initial Catalog=htm;Integrated Security=True";
            SqlConnection con = new SqlConnection(ConString);

            //string query = "Insert into GuestInfo(Guest ID,first name,last name,gender,martial status,phone number,email_address) values (" + guest_id + ",'" + first_name + "','" + last_name + "','" + gender_status + "','" + martial_status + "','" + phone_numb + "','" + email_id + "')";

            //SqlCommand cmd = new SqlCommand(query, con);
            con.Open();
            SqlCommand com = new SqlCommand("getguestinfo", con);
            com.CommandType = CommandType.StoredProcedure;
            com.Parameters.Add(new SqlParameter("@guestid", gus.guest_id));
            com.Parameters.Add(new SqlParameter("@firstname", gus.first_name));
            com.Parameters.Add(new SqlParameter("@lastname", gus.last_name));
            com.Parameters.Add(new SqlParameter("@gender", gus.gender_status));
            com.Parameters.Add(new SqlParameter("@martialsttus", gus.martial_status));
            com.Parameters.Add(new SqlParameter("@phonenumber", gus.phone_numb));
            com.Parameters.Add(new SqlParameter("@mailid", gus.email_id));

            //int id = Convert.ToInt32(
              com.ExecuteNonQuery();
            con.Close();
           // return id;

           back to the form coding is

            private void button8_Click(object sender, EventArgs e)
        {
            guests sgt=new guests();
            sgt.add();

        }


        private void button5_Click(object sender, EventArgs e)
        {
            tabControl1.SelectedIndex = 1;
            guests gst = new guests();
            gst.Guest_id = Convert.ToInt32(guest_id.Text.ToString());
            gst.First_name = first_name.Text.ToString();
            gst.Last_name = last_name.Text.ToString();
            gst.Gender_status = gender_status.Text.ToString();
            gst.Martial_status = martial_status.Text.ToString();
           // gst.Phone_numb = Convert.ToInt32(phone_numb.ToString());
            gst.Email_id = email_id.Text.ToString();
            gst.add();
            dataGridView1.DataSource = gst.displaydata();
        }


        and here is stored procedure code




ALTER Procedure getguestinfo
as

Select * from GuestInfo As G




       anyone tell about this problem????

Recommended Answers

All 11 Replies

Do you see any paramters in your stored procedure? No you do not. Then why are you providing them in lines 87-93?

then what i write in code...can u plzz tell me?

yeah i correct it but when i again debug then there is error in line number 69.....??

You didn't add a connection to the SqlDataAdapter. Change line 68 to

da.SelectCommand = new SqlCommand("select * from guestinfo", con);

but when i click add and view button then any inforamtion not show and add in gridview

and in sql database which i add a entry in guesttable this entry not view in gridview when i click vew button????

can u tell me plz

In line 70, right after you fill the dataset, you clear it, so there is nothing in it.

so what i wirte????

plzz anyone tell me???? =(

simple, now comment line 70.

yes i commented but not add info

your method named displaydata() returns a string and you are binding a string to the datasource of a grid, which can never happen.
change your return type from string to datatable or dataset and then bind the result to the gridview. it will work.
i suppose there is a problem with the basics.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.