Hello guys i have a question i have these codes
Imports System.Data
Imports System.Data.SqlClient
Module Connect
Public Conn As SqlConnection
Public Function GetConnect()
Conn = New SqlConnection("Server = SQL Server;" & "initial Catalog = BloodBank;" & " Trusted_Connection=yes")
Return Conn
End Function
End Module
Public Class BloodDonor
Private Sub TextBox5_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtState.TextChanged
End Sub
Private Sub Label6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label6.Click
End Sub
Private Sub Label5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label5.Click
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddNew.Click
Dim strBloodType As String = txtBloodType.Text
Dim strDonorName As String = txtDonorName.Text
Dim strEMail As String = txtEMail.Text
Dim strPhoneNumber As String = txtPhoneNumber.Text
Dim strLocation As String = txtLocation.Text
Dim strState As String = txtState.Text
Dim strStatus As String = txtStatus.Text
Dim strIDNumber As String = txtIDNumber.Text
Dim strCommand As String = "insert into BloodBank values('" & strBloodType & "', '" & strDonorName & "', '" & strEMail & "', '" & strPhoneNumber & "', '" & strLocation & "', '" & strState & "', '" & strStatus & "', '" & strIDNumber & ")"
Dim Command As SqlClient.SqlCommand = New SqlClient.SqlCommand(strCommand, GetConnect)
Command.CommandType = CommandType.Text
'' MsgBox(strCommand)
Conn.Open()
If (Command.ExecuteNonQuery().Equals(1)) Then
MsgBox("Information Stored In Database")
Else
MsgBox("Information Didn't Get Store In Database")
End If
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
End Sub
Private Sub BloodDonor_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
When i run it it gives me an error on Conn.Open()
i would really like your help this is the first time i've ever connected VB.Net to an SQL database.