I am trying to insert 3 textbox values into my database using a visual basic form, I have previously done this on another form and it worked correctly so I copied the code and changed the names to suit but I am getting the falling error: 'Addcustomer' not a member of 'sql'.
Any help will be appreciated.
Here is my code used on the form, this is where the error is underlined in blue:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
Sql.Addcustomer(addcustomerfname.Text, addcustomersname.Text, addcustomeremail.Text)
MsgBox("Customer Added")
addeditmembership.Show()
Me.Hide()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Okay I am very new to VB and am only doing it for a uni assignment so have just been following lecturer instructions. Here is my full code for the control file (this includes the working insert and the faulty one), I know its probably some stupid error but it's got me stumped.
Public Class SQLControl
Public SQLCon As New SqlConnection With {.ConnectionString = "Data Source=WADE\SQL2012;Initial Catalog=master;Integrated Security=True;"}
Public SQLCmd As SqlCommand
Public SQLDA As SqlDataAdapter
Public SQLDS As DataSet
Public Function HasConnection() As Boolean
Try
SQLCon.Open()
SQLCon.Close()
Return True
Catch ex As Exception
MsgBox(ex.Message)
End Try
Return False
End Function
Public Sub RunQuery(Query As String)
Try
SQLCon.Open()
' CREATE COMMAND
SQLCmd = New SqlCommand(Query, SQLCon)
'Fill Dataset
SQLDA = New SqlDataAdapter(SQLCmd)
SQLDS = New DataSet
SQLDA.Fill(SQLDS)
SQLCon.Close()
Catch ex As Exception
MsgBox(ex.Message )
'Close connection
If SQLCon.State = ConnectionState.Open Then
SQLCon.Close()
End If
End Try
End Sub
Public Sub Addmember(member_fname As String, member_sname As String, member_gender As String, member_dob As String,
member_address As String, member_postcode As String, member_email As String, member_contact_number As String,
member_registration As String, member_discount_rate As Integer)
Try
Dim strinsert As String = "INSERT INTO members (member_fname,member_sname,member_gender,member_dob,member_address,member_postcode,member_email,member_contact_number,member_registration,member_discount_rate " & _
")VALUES(" & _
"'" & member_fname & "'," & _
"'" & member_sname & "'," & _
"'" & member_gender & "'," & _
"'" & member_dob & "'," & _
"'" & member_address & "'," & _
"'" & member_postcode & "'," & _
"'" & member_email & "'," & _
"'" & member_contact_number & "'," & _
"'" & member_registration & "'," & _
"'" & member_discount_rate & "')"
SQLCon.Open()
SQLCmd = New SqlCommand(strinsert, SQLCon)
SQLCmd.ExecuteNonQuery()
SQLCon.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Public Sub Addcustomer(addcustomerfname As String, addcustomersname As String, addcustomeremail As String)
Try
Dim customerinsert As String = "INSERT INTO customers (customer_fname,customer_sname,customer_email " & _
")VALUES(" & _
"'" & addcustomerfname & "'," & _
"'" & addcustomersname & "'," & _
"'" & addcustomeremail & "')"
SQLCon.Open()
SQLCmd = New SqlCommand(customerinsert, SQLCon)
SQLCmd.ExecuteNonQuery()
SQLCon.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class