jimmysaunders
asked on
SQLDataAdapter throwing exception
Hello Experts,
I have the following stored procedure to insert a record in the table
@EmpId varchar(20),
@Department varchar(50),
@Title varchar(50),
@LastName varchar(50),
@FirstName varchar(50),
@Location varchar(50),
@Office varchar(50),
@Phone varchar(25),
@Fax varchar(25),
@Email varchar(50)l
AS
BEGIN
SET NOCOUNT ON;
Insert Into tblEmployees
(EmpId, Department,Title, EmpLastName, EmpFirstName,Location, Office, Phone, Fax, Email)
Values
(@EmpId, @Department, @Title, @LastName, @FirstName, @Location, @Office, @Phone, @Fax, @Email)
I am using this sp as InsertCommand of the SQLDataAdapter. Here is the C# code
con.Open();
SqlDataAdapter da = new SqlDataAdapter("Select EmpId,Department,EmpLastNa m as LastName, EmpFirstName as FirstName, Location, Office, Email, Phone, Fax from tblEmployees",con);
da.InsertCommand = new SqlCommand("InsertEmployee Record", con);
da.InsertCommand.CommandTy pe = CommandType.StoredProcedur e;
da.InsertCommand.Parameter s.Add("@Em pId",SqlDb Type.VarCh ar,20);
da.InsertCommand.Parameter s.Add("@De partment", SqlDbType. VarChar,50 );
da.InsertCommand.Parameter s.Add("@La stName",Sq lDbType.Va rChar,50);
da.InsertCommand.Parameter s.Add("@Fi rstName",S qlDbType.V arChar,50) ;
da.InsertCommand.Parameter s.Add("@Lo cation",Sq lDbType.Va rChar,50);
da.InsertCommand.Parameter s.Add("@Of fice",SqlD bType.VarC har,50);
da.InsertCommand.Parameter s.Add("@Em ail",SqlDb Type.VarCh ar,50);
da.InsertCommand.Parameter s.Add("@Ph one",SqlDb Type.VarCh ar,25);
da.InsertCommand.Parameter s.Add("@Fa x",SqlDbTy pe.VarChar ,25);
da.Update(table);
The last line throws an exception saying, "Procedure or function 'InsertEmployeeRecord' expects parameter '@EmpId', which was not supplied."
Whereas in the command window, I can see that EMPId is in the table.
>? table.Rows[0]["EmpId"]
"102275"
What am I doing wrong?
Thanks,
JS
I have the following stored procedure to insert a record in the table
@EmpId varchar(20),
@Department varchar(50),
@Title varchar(50),
@LastName varchar(50),
@FirstName varchar(50),
@Location varchar(50),
@Office varchar(50),
@Phone varchar(25),
@Fax varchar(25),
@Email varchar(50)l
AS
BEGIN
SET NOCOUNT ON;
Insert Into tblEmployees
(EmpId, Department,Title, EmpLastName, EmpFirstName,Location, Office, Phone, Fax, Email)
Values
(@EmpId, @Department, @Title, @LastName, @FirstName, @Location, @Office, @Phone, @Fax, @Email)
I am using this sp as InsertCommand of the SQLDataAdapter. Here is the C# code
con.Open();
SqlDataAdapter da = new SqlDataAdapter("Select EmpId,Department,EmpLastNa
da.InsertCommand = new SqlCommand("InsertEmployee
da.InsertCommand.CommandTy
da.InsertCommand.Parameter
da.InsertCommand.Parameter
da.InsertCommand.Parameter
da.InsertCommand.Parameter
da.InsertCommand.Parameter
da.InsertCommand.Parameter
da.InsertCommand.Parameter
da.InsertCommand.Parameter
da.InsertCommand.Parameter
da.Update(table);
The last line throws an exception saying, "Procedure or function 'InsertEmployeeRecord' expects parameter '@EmpId', which was not supplied."
Whereas in the command window, I can see that EMPId is in the table.
>? table.Rows[0]["EmpId"]
"102275"
What am I doing wrong?
Thanks,
JS
@title is missing
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.