V
Visual Systems AB \(Martin Arvidsson\)
Hi!
I have been trying for several hours now to get this SQLCommand to work...
Below is a snippet... I have cut away some code...
Inherits System.Web.UI.Page
Protected WithEvents SqlConnection As System.Data.SqlClient.SqlConnection
Protected WithEvents tbKundnummer As System.Web.UI.WebControls.TextBox
Protected WithEvents SqlCommand As System.Data.SqlClient.SqlCommand
Private Sub InitializeComponent()
Dim configurationAppSettings As System.Configuration.AppSettingsReader = New
System.Configuration.AppSettingsReader()
Me.SqlConnection = New System.Data.SqlClient.SqlConnection()
Me.SqlCommand = New System.Data.SqlClient.SqlCommand()
'
'SqlConnection
'
Me.SqlConnection.ConnectionString =
CType(configurationAppSettings.GetValue("SQL.Connection",
GetType(System.String)), String)
'
'SqlCommand
'
Me.SqlCommand.CommandText = "[InsertCustomer]"
Me.SqlCommand.CommandType = System.Data.CommandType.StoredProcedure
Me.SqlCommand.Connection = Me.SqlConnection
Me.SqlCommand.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@RETURN_VALUE",
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue,
False, CType(10, Byte), CType(0, Byte), "",
System.Data.DataRowVersion.Current, Nothing))
Me.SqlCommand.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@KundNummer_1",
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, False,
CType(10, Byte), CType(0, Byte), "tbKundnummer",
System.Data.DataRowVersion.Current, Nothing))
End Sub
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
SqlConnection.Open()
End Sub
Private Sub bnSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles bnSave.Click
SqlCommand.ExecuteNonQuery() // Executing this will popup a message
InsertCustomer is missing a parameter @Kundnummer_1
End Sub
Why does this not work?
If i use
SqlCommand.Parameters.Add("@Kundnummer_1", tbKundnummer.text)
SqlCommand.ExecuteNonQuery
it will work...
Am i missing something?
Regards
Martin Arvidsson
I have been trying for several hours now to get this SQLCommand to work...
Below is a snippet... I have cut away some code...
Inherits System.Web.UI.Page
Protected WithEvents SqlConnection As System.Data.SqlClient.SqlConnection
Protected WithEvents tbKundnummer As System.Web.UI.WebControls.TextBox
Protected WithEvents SqlCommand As System.Data.SqlClient.SqlCommand
Private Sub InitializeComponent()
Dim configurationAppSettings As System.Configuration.AppSettingsReader = New
System.Configuration.AppSettingsReader()
Me.SqlConnection = New System.Data.SqlClient.SqlConnection()
Me.SqlCommand = New System.Data.SqlClient.SqlCommand()
'
'SqlConnection
'
Me.SqlConnection.ConnectionString =
CType(configurationAppSettings.GetValue("SQL.Connection",
GetType(System.String)), String)
'
'SqlCommand
'
Me.SqlCommand.CommandText = "[InsertCustomer]"
Me.SqlCommand.CommandType = System.Data.CommandType.StoredProcedure
Me.SqlCommand.Connection = Me.SqlConnection
Me.SqlCommand.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@RETURN_VALUE",
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue,
False, CType(10, Byte), CType(0, Byte), "",
System.Data.DataRowVersion.Current, Nothing))
Me.SqlCommand.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@KundNummer_1",
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, False,
CType(10, Byte), CType(0, Byte), "tbKundnummer",
System.Data.DataRowVersion.Current, Nothing))
End Sub
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
SqlConnection.Open()
End Sub
Private Sub bnSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles bnSave.Click
SqlCommand.ExecuteNonQuery() // Executing this will popup a message
InsertCustomer is missing a parameter @Kundnummer_1
End Sub
Why does this not work?
If i use
SqlCommand.Parameters.Add("@Kundnummer_1", tbKundnummer.text)
SqlCommand.ExecuteNonQuery
it will work...
Am i missing something?
Regards
Martin Arvidsson