What the...?

  • Thread starter Thread starter Bill
  • Start date Start date
B

Bill

Got a form that pulls data and allows for the user to enter a
response in a textbox and I have a button that is supposed to push this
reponse text back to the database for that record when clicked. HOWEVER
all that is happening when I do this is the data field that is supposed
to be updated with the text from the textbox goes from being NULL to just
being blank(almost like its updating, but not updating it with the text
in the textbox)
What the heck am I missing here?

Here is my button click code:

Private Sub btnAddResponse_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnAddResponse.Click
Dim cnn As SqlConnection = New SqlConnection( _
"Data Source= CLT-SP2K3;Initial
Catalog=LittleProjectSiteDb;" & _
"UID=ronaldmcdonald;PWD=bigmac")
Dim cmdUpdate As SqlCommand = cnn.CreateCommand()
cmdUpdate.CommandType = CommandType.StoredProcedure
cmdUpdate.CommandText = "addresponse"
cmdUpdate.Parameters.Add(New SqlParameter( _
"@ID", SqlDbType.Int, 9))
cmdUpdate.Parameters("@ID").Value = lblTest.Text
cmdUpdate.Parameters.Add(New SqlParameter( _
"@Response", SqlDbType.Char, 200))
cmdUpdate.Parameters("@Response").Value = txtResponse.Text
Dim da As SqlDataAdapter = New SqlDataAdapter
da.UpdateCommand = cmdUpdate
cnn.Open()
cmdUpdate.ExecuteNonQuery()
End Sub

Here is my stored procedure:

CREATE PROCEDURE addresponse
@ID numeric, @Response char(200)
AS
UPDATE WachoviaRFI SET
RFI_Response=@Response
WHERE
RFI_Number=@ID
GO
 
You might want to change couple of things and try,

1. Include the Directions for the parameters.

cmdUpdate.Parameters("@ID").direction =
ParameterDirection.Input

2. I dont think you need these...TO
Dim cmdUpdate As SqlCommand
cmdUpdate = new SqlCommand("addresponse",cnn)


Thanks,
-Shan

Dim cnn As SqlConnection = New SqlConnection( _
"Data Source= CLT-SP2K3;Initial
Catalog=LittleProjectSiteDb;" & _
"UID=ronaldmcdonald;PWD=bigmac")
Dim cmdUpdate As SqlCommand = cnn.CreateCommand()
cmdUpdate.CommandType = CommandType.StoredProcedure
cmdUpdate.CommandText = "addresponse"
cmdUpdate.Parameters.Add(New SqlParameter( _
"@ID", SqlDbType.Int, 9))
cmdUpdate.Parameters("@ID").Value = lblTest.Text
cmdUpdate.Parameters.Add(New SqlParameter( _
"@Response", SqlDbType.Char, 200))
cmdUpdate.Parameters("@Response").Value = txtResponse.Text
Dim da As SqlDataAdapter = New SqlDataAdapter
da.UpdateCommand = cmdUpdate
cnn.Open()
cmdUpdate.ExecuteNonQuery()
End Sub







Dim cnn As SqlConnection = New SqlConnection( _
 
This did not work...Its almost like its not picking up the text that I
type into the Textbox and is just entering in blank data. I.E. ""
Anyone else got any ideas?
TIA,
Bill
 
Your code looks ok.
Few checks you can do though that might help you pin point
the problem area.

1. Are you looking for postbacks in your Page_Load
function? You may be initializing the form on postbacks
too.
2. Have you checked in debug mode if you are getting
anything from txtResponse.Text.
3. If you have permissions you can turn on SQL profiler
and see what the SQL command that's being passed to the
SQL server from ADO.NET.

HTH,
Suresh.
 
Sometimes its the little things that get ya..
I forgot to put in If Not Postback in my page load..

Thanks to all who helped!
 
Back
Top