chicago75 Posted March 8, 2003 Posted March 8, 2003 (edited) All, THis is confusing, but I am probably missing something very obvious. When this code is executed, the debug locals show the command text to have values (CID=19, Custfnu=brian, etc...) but the information is not written to the DB.. It is my understanding that with the string and the connection in the declaration, I do not need the ExecuteNonQuery statement. Is this correct? WHy is it not working? Here is the code... Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim SQLCN As New SqlClient.SqlConnection("Server=ICS-SVR1;User ID=sa;Password=;Database=ICS-DISPATCH") SQLCN.Close() SQLCN.Open() Dim SqlDataAdapter1 As New SqlDataAdapter("UPDATE custdb SET custfn=" & "'" & custfnu.Text & "' , " & "custln= '" & custlnu.Text & "' ," & "custcn= '" & custcnu.Text & "', " & "custadd1='" & custadd1u.Text & "' , " & "custadd2='" & custadd2u.Text & "' , " & "custcity='" & custcityu.Text & "' , " & "custst= " & "'" & custstu.Text & "', " & "custZIP='" & custzipu.Text & "', " & "custph='" & custphu.Text & "', " & "custnote='" & CustNoteu.Text & "' " & "WHERE cid=" & cidu.Text & ";", SQLCN) Me.Close() End Sub Edited March 8, 2003 by chicago75 Quote
Moderators Robby Posted March 8, 2003 Moderators Posted March 8, 2003 For Update,Delete Insert queries you can use the Command object and the Excecute method.... Here's a simple function to do this... Friend Function ExecuteNonQuery(ByVal sSql As String) As Integer Dim cmd As SqlCommand Dim con As New SqlConnection(YOUR_CONNECTION_STRING) Dim recordsAffected As Integer Try If con.State = ConnectionState.Closed Then con.Open() cmd = New SqlCommand(sSql, con) recordsAffected = cmd.ExecuteNonQuery() Catch ex As Exception MessageBox.Show(ex.ToString) recordsAffected = -1 Finally If con.State = ConnectionState.Open Then con.Close() If Not cmd Is Nothing Then cmd.Dispose() End Try Return recordsAffected 'returns more than 0 if successful End Function Quote Visit...Bassic Software
chicago75 Posted March 8, 2003 Author Posted March 8, 2003 Once again Robby, your right!!!! It Works!!!! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.