J
JD
I have built a windowsform application. I want to insert a new record into a
SQL database using a stored procedure. When I run the app I get an error
message "Line 1: Incorrect syntax near 'usp_AddData'". When I exec the
stored procedure in Query Analyser it works. I have a similar app where the
the same code works without errors. I have compare both apps and have not
been able to find a difference. Any ideas?
Here is the code I use if it helps:
Public CnStr As String = "packet size=4096;integrated security=SSPI;data
source=""(local)"";persist security info=False;initial catalog=LakeSurvey"
Public Cn As New SqlConnection(CnStr)
Public Sqlcm As SqlClient.SqlCommand
Private Sub btnSaveLakeData_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSaveLakeData.Click
Try
Dim Cn As New SqlConnection(CnStr)
Dim SqlCm As SqlClient.SqlCommand = New
SqlClient.SqlCommand("usp_AddLakeData1", Cn)
Dim prmLD1 As SqlClient.SqlParameter = SqlCm.Parameters.Add("@HydroID",
SqlDbType.Int, 4)
Dim prmLD2 As SqlClient.SqlParameter = SqlCm.Parameters.Add("@SurveyDate",
SqlDbType.SmallDateTime, 4)
prmLD1.Value = Me.lblHydroID.Text
prmLD2.Value = Me.dtSurveyDate.Value
Cn.Open()
SqlCm.ExecuteNonQuery()
Cn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
SQL database using a stored procedure. When I run the app I get an error
message "Line 1: Incorrect syntax near 'usp_AddData'". When I exec the
stored procedure in Query Analyser it works. I have a similar app where the
the same code works without errors. I have compare both apps and have not
been able to find a difference. Any ideas?
Here is the code I use if it helps:
Public CnStr As String = "packet size=4096;integrated security=SSPI;data
source=""(local)"";persist security info=False;initial catalog=LakeSurvey"
Public Cn As New SqlConnection(CnStr)
Public Sqlcm As SqlClient.SqlCommand
Private Sub btnSaveLakeData_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSaveLakeData.Click
Try
Dim Cn As New SqlConnection(CnStr)
Dim SqlCm As SqlClient.SqlCommand = New
SqlClient.SqlCommand("usp_AddLakeData1", Cn)
Dim prmLD1 As SqlClient.SqlParameter = SqlCm.Parameters.Add("@HydroID",
SqlDbType.Int, 4)
Dim prmLD2 As SqlClient.SqlParameter = SqlCm.Parameters.Add("@SurveyDate",
SqlDbType.SmallDateTime, 4)
prmLD1.Value = Me.lblHydroID.Text
prmLD2.Value = Me.dtSurveyDate.Value
Cn.Open()
SqlCm.ExecuteNonQuery()
Cn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub