Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
nhaas
Yak Posting Veteran
90 Posts |
Posted - 2007-03-06 : 01:11:55
|
| I am having some issues with trying to run a stored procedure in Visual Basic. I have gotten the procedure that inserts a new row but I dont get the data inserted. Hopefully someone can point me to my errors in my ways.''''Dim cmd As New SqlClient.SqlCommand()Dim MySqlConnection ......cmd.CommandType = CommandType.StoredProcedurecmd.CommandText = "TUNITS"cmd.Connection = MySqlConnectionDim p As New SqlClient.SqlParameterp.ParameterName = "@UNITS1"p.Value = "1"cmd.Parameters.Add(p)Dim p1 As New SqlClient.SqlParameterp1.ParameterName = "@UNITS2"p1.Value = "Blah2"cmd.Parameters.Add(p1)Trycmd.Connection.Open()cmd.ExecuteNonQuery()cmd.Connection.Close()MsgBox("maybe")CatchMsgBox("nope")End Try test Insert Procedure.CREATE PROCEDURE [TUNITS] ASDECLARE @UNITS1 numeric(8)DECLARE @UNITS2 numeric(8)beginINSERT INTO test([test1], [test2])values(@UNITS1, @UNITS2)endGOSQL2000 and VB thank you for the help |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-03-06 : 01:23:23
|
| Your SP is having two numeric parameters, but you are passing varchar value for the second parameter...Why?Also, have you tried running this SP from Query Analyzer and check whether data gets inserted?Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
nhaas
Yak Posting Veteran
90 Posts |
Posted - 2007-03-06 : 11:17:34
|
| Silly question, how do I check the Stored procedure through Query analyzer? (newbe question for this I guess...)you are correct I did some updating to the Insert but i get nothing inserted, except for a row...... cmd.CommandType = CommandType.StoredProcedure cmd.CommandText = "TUNITS" cmd.Connection = MySqlConnection Dim IFirst As Integer IFirst = 1 Dim Isecond As Integer Isecond = 1 Dim p1 As New SqlClient.SqlParameter("@UNITS1", IFirst) Dim p2 As New SqlClient.SqlParameter("@UNITS2", Isecond) Try cmd.Connection.Open() cmd.ExecuteNonQuery() cmd.Connection.Close() MsgBox("maybe") Catch MsgBox("nope") End Try |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-03-06 : 11:26:22
|
To run SP through Query Analyzer, type this in QA:exec TUNITS @UNITS1=1, @UNITS2=1 Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
nhaas
Yak Posting Veteran
90 Posts |
Posted - 2007-03-06 : 12:37:07
|
| My bad, stored procedure was bad.....CREATE PROCEDURE TUNITS(@UNITS1 numeric(8),@UNITS2 numeric(8))ASINSERT INTO test ([test1], [test2])values(@UNITS1, @UNITS2)GO |
 |
|
|
|
|
|
|
|