Hi All,
This I am hoping will be simple I have the following code:
I've removed the connection string details but the error I am getting is:
An SqlParameter with ParameterName 'str_field' is not contained by this SqlParameterCollection.
I am getting two values that are given by the user, aos_code and aos_period,I then need the str_field. I can can pass the parameter ok, but the problem is I can't get a value back from the table the error occurs at this line:
I am very new to and have been trying now for hours, any one any ideas?...
This I am hoping will be simple I have the following code:
VB.NET:
Imports System.Data.OleDb
Imports System.Data.SqlClient
Partial Class _Default
Inherits System.Web.UI.Page
Public aos_code, aos_period, str_field As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
lblDetails.Text = Right(HttpContext.Current.User.Identity.Name, Len(HttpContext.Current.User.Identity.Name) - 8) + " :: " + HttpContext.Current.Server.MachineName + " :: " + Format(Now(), "dd/MM/yyyy h:mm")
If (aos_code <> "") And (aos_period <> "") Then
MsgBox("Your aos_code is " & aos_code & "Your aos_period is " & aos_period)
End If
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
' Get SqlDataSource Select Parameters
Dim txt As New TextBox()
txt = CType(FindControl("TextBox1"), TextBox)
aos_code = txt.Text
txt = CType(FindControl("TextBox2"), TextBox)
aos_period = txt.Text
Dim sqldbconn As New Data.SqlClient.SqlConnection
Dim ds As New DataSet
Dim da As New SqlClient.SqlDataAdapter
Dim cmd As New SqlClient.SqlCommand
sqldbconn.ConnectionString = "Data Source=*********;Initial Catalog=******;Integrated Security=True"
cmd.CommandType = CommandType.Text
cmd.CommandText = "SELECT * FROM ****** WHERE aos_code = @aos_code AND aos_period = @aos_period"
cmd.Parameters.AddWithValue("@aos_code", SqlDbType.VarChar).Value = aos_code
cmd.Parameters.AddWithValue("@aos_period", SqlDbType.VarChar).Value = aos_period
Dim newSTR As Integer
newSTR = cmd.Parameters("str_field").Value
cmd.Connection = sqldbconn
da.SelectCommand = cmd
sqldbconn.Open()
'for testing
MsgBox("Your aos_code is " & aos_code & "Your aos_period is " & aos_period & "Your str_field is " & newSTR)
da.Fill(ds)
sqldbconn.Close()
End Sub
End Class
I've removed the connection string details but the error I am getting is:
An SqlParameter with ParameterName 'str_field' is not contained by this SqlParameterCollection.
I am getting two values that are given by the user, aos_code and aos_period,I then need the str_field. I can can pass the parameter ok, but the problem is I can't get a value back from the table the error occurs at this line:
VB.NET:
newSTR = cmd.Parameters("str_field").Value
I am very new to and have been trying now for hours, any one any ideas?...