What the...?

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
 
S

Shan

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( _
 
B

Bill

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
 
S

Suresh

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.
 
B

Bill

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top