[RESOLVED] what is wrong with this syntax
Dim sqlcmd As New SqlCommand("sprInsertUser", oSQLConn1)
sqlcmd.Parameters.Add("@fname", SqlDbType.Char).Value = txtFname.Text
sqlcmd.Parameters.Add("@town", SqlDbType.Char).Value = txttown.Text
sqlcmd.Parameters.Add("@carreg", SqlDbType.Char).Value = txtcarreg.Text
oSQLConn1.Open()
sqlcmd.ExecuteNonQuery()
oSQLConn1.Close()
i get the error
Incorrect syntax near 'sprInsertUser'.
Re: what is wrong with this syntax
Do you get this on the line ExecuteNonQuery?
Can you post the SP you are using...well at least the DECLARE bits from the top.
The param types must match the SP params exactly.
Woof
Re: what is wrong with this syntax
ive changed it to this
VB Code:
oSQLConn1.ConnectionString = "Data Source=(local);" & _
"Initial Catalog=StoreProc;" & _
"Integrated Security=SSPI"
strSql = "EXECUTE sprInsertUser"
Dim sqlcmd As New SqlCommand(strSql, oSQLConn1)
sqlcmd.Parameters.Add("@fname", SqlDbType.Char).Value = txtFname.Text
sqlcmd.Parameters.Add("@town", SqlDbType.Char).Value = txttown.Text
sqlcmd.Parameters.Add("@carreg", SqlDbType.Char).Value = txtcarreg.Text
oSQLConn1.Open()
sqlcmd.ExecuteNonQuery()
oSQLConn1.Close()
but now im on this error
Procedure 'sprInsertUser' expects parameter '@fname', which was not supplied.
the SP is
Code:
CREATE PROCEDURE sprInsertUser
(
@fname char(10),
@town char(10),
@carreg char(10)
)
AS
INSERT INTO tbUser
(fname, town, carreg)
VALUES
(@fname, @town, @carreg)
GO
Re: what is wrong with this syntax
Change the source SQL from
EXECUTE sprInsertUser
to
EXECUTE sprInsertUser @fname, @town, @carreg
And preserve all the rest of the code you have
Re: what is wrong with this syntax
thats the job,
i spent all day yesterday trying to get that to work, lol
in this morning checked the thread and 2 seconds job done,
THANKS
do you know of any good books for stored procedures and asp.net,
i think i should get one
Re: [RESOLVED] what is wrong with this syntax
You could also set the commandType to StoredProcedure:
VB Code:
Dim sqlcmd As New SqlCommand("sprInsertUser", oSQLConn1)
sqlcmd.CommandType = CommandType.StoredProcedure
'ect....