Hi,
I have been running around in circles trying to figure out why this won't work and have finally resorted to seeking advice.
I have a datagrid that is used to display my QueryCode table (SQL server). I am getting the Table values from a dataset created by my data adapter. I have a button and two textboxes (for entering the values). When I click on the button I just want to be able to pass an sql statement with the values from the textboxes, to an sqlcommand who will add the record to the database, but it just doesn't seem to want to process it!
What am I doing wrong...!
Here's the code:
Code:Private Sub AddButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddButton.Click Dim query_code As String Dim query_ref As String Dim sql_add As String query_code = txtQueryCode.Text query_ref = txtQueryRef.Text sql_add = "INSERT INTO QueryCode(QueryCode, QueryRef) VALUES (" + query_code + "," + query_ref + ")""" 'SqlConnection1 is the connection created with the DataAdapter SqlCommand1.Connection = SqlConnection1 SqlCommand1.CommandType = CommandType.Text 'Setting the command text to the SQL statement declared above SqlCommand1.CommandText = sql_add SqlConnection1.Open() Try SqlCommand1.ExecuteNonQuery() Catch ex As Exception Label1.Text = ex.ToString End Try SqlConnection1.Close() End Sub




Reply With Quote