need help with sqlCommand

Results 1 to 3 of 3

Thread: need help with sqlCommand

  1. #1
    Join Date
    Dec 1969

    Default need help with sqlCommand

    I am trying to use sqlcommand and my code gives me the error <BR><BR>An SqlParameter with ParameterName &#039;@authorID&#039; is not contained by this SqlParameterCollection. <BR><BR>What gives? I provided the code below<BR><BR> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<BR> &#039;Put user code to initialize the page here<BR> Dim dtrAuthor As System.Data.SqlClient.SqlDataReader<BR> Dim AuthorID As String<BR><BR> AuthorID = Request.QueryString("id")<BR> If IsNothing(AuthorID) Then<BR> Response.Redirect("AuthorMaster.aspx")<BR> End If<BR><BR> Dim conn As New System.Data.SqlClient.SqlConnection("data source=dpnwnt68;initial catalog=pubs; user id=myid;password=test;")<BR> Dim sqlCommand As New System.Data.SqlClient.SqlCommand<BR> sqlCommand.CommandText = "Select * from authors where au_id=@authorID"<BR> sqlCommand.CommandType = CommandType.Text<BR> sqlCommand.Connection = conn<BR> sqlCommand.Parameters("@authorID").Value = AuthorID<BR><BR> dtrAuthor = sqlCommand.ExecuteReader<BR> If dtrAuthor.Read Then<BR> lblFirstName.Text = dtrAuthor("au_fname")<BR> lblLastName.Text = dtrAuthor("au_lname")<BR> lblPhone.Text = dtrAuthor("phone")<BR> End If<BR> conn.Close()<BR> End SubteReader

  2. #2
    Join Date
    Dec 1969

    Default Some working code

    is in the second second of this page<BR><BR><BR>

  3. #3
    Join Date
    Dec 1969

    Default RE: need help with sqlCommand

    You forgot to add the parameter.<BR><BR>sqlCommand.Parameters.Add("@auth orID")<BR>sqlCommand.Parameters("@authorID").Value = AuthorID

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts