sql - "Procedure or function 'UPDATE' expects parameter '@Id', which was not supplied" in Windows Form -


we created windows form update table in sql server.

first click enter id retrieve details database, after changing data, when click on update button, error:

procedure or function 'update' expects parameter '@id', not supplied.

windows form design :

click here

error :

click here

code windows form:

public partial class update : form {     string connectionstring = @"data source=amar;initial catalog=hotel;integrated security=true";      public update()     {         initializecomponent();     }      private void button1_click(object sender, eventargs e)     {         {             testobject t = null;             string spname = "get";             //string querytext = "select * testtable id = " +txtid.text;             sqlconnection conn = new sqlconnection(connectionstring);             //sqlcommand com = new sqlcommand(spname, conn);             sqlcommand com = new sqlcommand(spname, conn);             com.parameters.addwithvalue("@id", id.text);             com.commandtype = commandtype.storedprocedure;              conn.open();              using (sqldatareader reader = com.executereader())             {                 t = new testobject();                  while (reader.read())                 {                     t.id = reader["id"].tostring();                     t.status = reader["status"].tostring();                     t.fname = reader["firstname"].tostring();                     t.lname = reader["lastname"].tostring();                     t.addr = reader["address"].tostring();                     t.city = reader["city"].tostring();                     t.state = reader["state"].tostring();                     t.country = reader["country"].tostring();                     t.phoneno = reader["phoneno"].tostring();                     t.email = reader["emailid"].tostring();                     t.pin = reader["pincode"].tostring();                     t.checkin = reader["checkin"].tostring();                     t.checkout = reader["checkout"].tostring();                     t.adultno = reader["adultno"].tostring();                     t.childno = reader["infantno"].tostring();                     t.infantno = reader["infantno"].tostring();                     t.roomno = reader["roomno"].tostring();                 };             }              statustxt.text = t.status;             txtfname.text = t.fname;             txtlname.text = t.lname;             txtaddr.text = t.addr;             city.text = t.city;             state.text = t.state;             country.text = t.country;             phoneno.text = t.phoneno;             emailid.text = t.email;             pincode.text = t.pin;             checkin.text = t.checkin;             checkout.text = t.checkout;             adult.text = t.adultno;             child.text = t.childno;             infant.text = t.infantno;             roomno.text = t.roomno;         }     }      private void btnupdate_click(object sender, eventargs e)     {         string stat = statustxt.text;         string firstname = txtfname.text;         string lastname = txtlname.text;         string address=txtaddr.text;         string cities=city.text;         string states= state.text;         string  countries =country.text;         string  phonenos= phoneno.text;;         string  emailid= emailid.text;         string pincode=pincode.text;         string cin=checkin.text;         string  cout=checkout.text;         string  adultno=adult.text;         string  childno=child.text;         string infantno=infant.text;         string roomnos=roomno.text;          testobject obj = new testobject();          obj.stat=statustxt.text;         obj.firstname = txtfname.text;         obj.lastname = txtlname.text;         obj.address=txtaddr.text;         obj.cities=city.text;         obj.states= state.text;         obj.countries =country.text;         obj.phonenos= phoneno.text;;         obj.emailid= emailid.text;         obj.pincode=pincode.text;         obj.cin=checkin.text;         obj.cout=checkout.text;         obj.adultno=adult.text;         obj.childno=child.text;         obj.infantno=infant.text;         obj.roomnos=roomno.text;          string spname = "update";          sqlconnection conn = new sqlconnection(connectionstring);         sqlcommand com = new sqlcommand(spname, conn);          conn.open();          com.parameters.addwithvalue("@stat", obj.stat);         com.parameters.addwithvalue("@firstname", obj.firstname);         com.parameters.addwithvalue("@lastname", obj.lastname);         com.parameters.addwithvalue("@address", obj.address);         com.parameters.addwithvalue("@cities", obj.cities);         com.parameters.addwithvalue("@states", obj.states);         com.parameters.addwithvalue("@countries", obj.countries);         com.parameters.addwithvalue("@phonenos", obj.phonenos);         com.parameters.addwithvalue("@emailid", obj.emailid);         com.parameters.addwithvalue("@pincode", obj.pincode);         com.parameters.addwithvalue("@cin", obj.cin);         com.parameters.addwithvalue("@cout", obj.cout);         com.parameters.addwithvalue("@adultno", obj.adultno);         com.parameters.addwithvalue("@childno", obj.childno);         com.parameters.addwithvalue("@infantno", obj.infantno);         com.parameters.addwithvalue("@roomnos", obj.roomnos);          com.commandtype = commandtype.storedprocedure;          com.executenonquery();         conn.close();          messagebox.show("customer details updated in system");     } } 

sql server stored procedure:

alter procedure [dbo].[update]      @id int,     @stat nvarchar(100),     @firstname nvarchar(100),     @lastname nvarchar(100),     @address nvarchar(100),     @cities nvarchar(100),     @states nvarchar(100),     @countries nvarchar(100),     @phonenos int,     @emailid nvarchar(100),     @pincode int,     @cin nvarchar(100),     @cout nvarchar(100),     @adultno int,     @childno int,     @infantno int,      @roomnos int begin set nocount on;  -- insert statements procedure here update [hotel].[dbo].[details] set [status] = @stat,    [firstname] = @firstname,   [lastname] = @lastname,   [address] = @address,   [city] = @cities,   [state] =@states ,   [country] = @countries,   [phoneno] = @phonenos,   [emailid] = @emailid,   [pincode] = @pincode,   [checkin] = @cin,   [checkout] = @cout,   [adultno] = @adultno,   [childno] = @childno,   [infantno] = @infantno,   [roomno] = @roomnos id = @id  end 

a. mitch wheat wrote in comments, never use keywords procedures names.

b. marc_s wrote in comment - stop using .addwithvalue(). read article links to.

c. never provide @id parameter command , why error.

d. has nothing winforms.

e. in future, please provide relevant code. if problem in update button click, don't need see entire form class, button click event handler.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -