SqlDataAdapter & Stored Procedure

  • Thread starter Thread starter Gurkan
  • Start date Start date
G

Gurkan

Can we use SqlDataAdapter.InsertCommand or Delete, Uptade command with
stored procedure ?

For example:

if i use this code then I get a error message

Procedure :

CREATE PROCEDURE SpDeneme AS
DECLARE @Alan1 int
INSERT INTO TblDeneme (Alan1) VALUES (@Alan1)
GO

Code:

SqlCommand oCmdInsert = new SqlCommand();
oCmdInsert.Connection = Db.CNN;
oCmdInsert.CommandType = CommandType.Text ;
oCmdInsert.CommandType = CommandType.StoredProcedure;
oCmdInsert.CommandText = "SpDeneme";
oCmdInsert.Parameters.Add("@Alan1", SqlDbType.Int,4,"Alan1");
oAdp.InsertCommand = oCmdInsert;
oAdp.Update(oTbl);


But if I use this code then all is ok. I use here CommandType.Text

SqlCommand oCmdInsert = new SqlCommand();
oCmdInsert.Connection = Db.CNN;
oCmdInsert.CommandType = CommandType.Text ;
oCmdInsert.CommandText = "INSERT INTO TblDeneme (Alan1) VALUES (@Alan1)";
oCmdInsert.Parameters.Add("@Alan1", SqlDbType.Int,4,"Alan1");
oAdp.InsertCommand = oCmdInsert;
oAdp.Update(oTbl);




GD...
 
Message is:
"Procedure has no parameters and arguments were supplied"

I think, SqlDataAdapter.Update function can't give the value to the
parameter.


GD...
 
I found the answer. I used onyl declaration, not parameter. Correct code is
like that:

CREATE PROCEDURE SpDeneme @Alan1 int
AS
INSERT INTO TblDeneme (Alan1) VALUES (@Alan1)
GO


Thk for answer
microsoft.public.tr.dotnet
Ozgur Yaþar



GD...
 
Back
Top