Here is my code.
I have access to the db from Vb.net, the column get the data from it, but when I insert new row to the table, nothing happen. No error message at all, and the new record doesn't appear in my db.
I am still learning here, and I would appreciate any help.
Thanks
I have access to the db from Vb.net, the column get the data from it, but when I insert new row to the table, nothing happen. No error message at all, and the new record doesn't appear in my db.
I am still learning here, and I would appreciate any help.
VB.NET:
Private Function Db_Connect() As Boolean
If sqlconn.State = ConnectionState.Closed Then
sqlconn.ConnectionString = connString
sqlconn.Open()
MsgBox("Connected!")
End If
Return Nothing
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If Me.ValidateChildren() Then
Try
Db_Connect()
sqlquery.CommandText = "Insert into Units ( [B_ID], [F_ID], [U_Number], [Rooms], [Current_Tenant], [Default_Rent], [Current_Rent] ) Values ( " & CStr(Buildings_List.SelectedValue) & ", " & CStr(Floors_List.SelectedValue) & ", '" & Unit_Name.Text & "', '" & Rooms.Text & "', 19, " & Rent.Text & ", 0)"
sqlquery.Connection = sqlconn
'Dim msg As String = sqlquery.ExecuteNonQuery()
Try
sqlquery.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show(ex.Message & " - " & ex.Source)
End Try
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End If
End Sub
Thanks