Edit in Datagridview

too many arguments in stored procedure

Page 1 of 1

4 Replies - 3095 Views - Last Post: 10 November 2010 - 03:49 AM Rate Topic: -----

#1 sandysooso   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 06-May 09

Edit in Datagridview

Posted 09 November 2010 - 11:59 AM

i have a form contains datagridview connected to database and filled by Customer table which contains customer_no cust_name cust_bd address..i can change/edit in the cells through a stored procedure and these changes go to database but after that there is error appeared
Procedure or function update_customer has too many arguments specified.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace tryzz
{
    public partial class Customer : Form
    {
    
        
       

        public Customer()
        {
            InitializeComponent();

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the '_2BassignmentDataSet.Customer' table. You can move, or remove it, as needed.
            this.customerTableAdapter.Fill(this._2BassignmentDataSet.Customer);


            dataGridView1.ReadOnly = false;




        }
        private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            string connstrng = "server=.;database=2Bassignment;Integrated Security=true";
            SqlConnection cnn = new SqlConnection(connstrng);
            cnn.Open();
            SqlCommand cmd = new SqlCommand("update_customer", cnn);
            cmd.CommandType = CommandType.StoredProcedure;
           





            for (int i = 1; i < dataGridView1.Rows.Count; i++)
            {

                string f= dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].FormattedValue.ToString();
                string v=dataGridView1.Rows[e.RowIndex].Cells[0].FormattedValue.ToString();
                string w = dataGridView1.Rows[e.RowIndex].Cells[1].FormattedValue.ToString();
                string x = dataGridView1.Rows[e.RowIndex].Cells[2].FormattedValue.ToString();
                string y = dataGridView1.Rows[e.RowIndex].Cells[3].FormattedValue.ToString();
               
                cmd.Parameters.Add(new SqlParameter("@customer_no", SqlDbType.Int, 0, "customer_no")).Value = v;
                cmd.Parameters.Add(new SqlParameter("@cust_name", SqlDbType.NVarChar, 25, "cust_name")).Value = w;
                cmd.Parameters.Add(new SqlParameter("@cust_bd", SqlDbType.Date, 0, "cust_bd")).Value = x;
                cmd.Parameters.Add(new SqlParameter("@address", SqlDbType.NVarChar, 35, "address")).Value = y;

              
                SqlDataReader rdr = cmd.ExecuteReader();

               
                   // string b= dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].FormattedValue.ToString();
                rdr.Close();
              
            }

            
        }

       }
}




and the stored procedure in the database
USE [2Bassignment]
GO

/****** Object:  StoredProcedure [dbo].[update_customer]    Script Date: 11/09/2010 20:24:22 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[update_customer]
(
@customer_no int,
@cust_name nvarchar(25),
@cust_bd date,
@address nvarchar(35)
)
AS
BEGIN
update Customer
set
[email protected]_name,
[email protected]_bd,
[email protected]
where [email protected]_no
END



GO






Is This A Good Question/Topic? 0
  • +

Replies To: Edit in Datagridview

#2 elbielefeld   User is offline

  • D.I.C Head

Reputation: 70
  • View blog
  • Posts: 217
  • Joined: 18-May 10

Re: Edit in Datagridview

Posted 09 November 2010 - 12:21 PM

Try it with clearing the parameters before setting them. You add them multiple times in the loop.
Was This Post Helpful? 1
  • +
  • -

#3 sandysooso   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 06-May 09

Re: Edit in Datagridview

Posted 09 November 2010 - 12:32 PM

View Postelbielefeld, on 09 November 2010 - 11:21 AM, said:

Try it with clearing the parameters before setting them. You add them multiple times in the loop.


yes, it works with passing a parameter to a selected number but i want to work all over the datagridview for any selected cell...of course i will not write all the ids of the table in order to edit in it...so how can i fix this problem..
Thank you
Was This Post Helpful? 0
  • +
  • -

#4 sandysooso   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 06-May 09

Re: Edit in Datagridview

Posted 10 November 2010 - 03:37 AM

Hii
anyone can reply, please?
where can i use clear??
clear()
Thanks

Sandy

This post has been edited by sandysooso: 10 November 2010 - 03:40 AM

Was This Post Helpful? 0
  • +
  • -

#5 sandysooso   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 06-May 09

Re: Edit in Datagridview

Posted 10 November 2010 - 03:49 AM

View Postsandysooso, on 10 November 2010 - 02:37 AM, said:

Hii
anyone can reply, please?
where can i use clear??
clear()
Thanks

Sandy


cmd.paramaters.clear();
after the cmd.executereader
yes, it workssss
i am very thankful 4 u :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1