hi dear coders my problem is connecting my vb.net project to the database tables in sql server so can any one help me please the code is ok and there is no syntax erros i declared the conection code in seperate class and wana use it from there have look at this ....this my code
The Declartion part in Class one
Imports System.Data.SqlClient
Public Class Class1
Public Shared sqlcon As New SqlConnection
End Class
and this is the code in form login
Imports System.Data.SqlClient
Public Class frmLogin
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Class1.sqlcon.ConnectionString = "Data Source=TOSHIBA-PC\SQLEXPRESS;initial catalog=Employes;integrated security=true"
MsgBox("تم الاتصال بنجاح", MsgBoxStyle.Exclamation)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If txtID.Text = "" Then
MsgBox("ادخل رقم المستخدم", MsgBoxStyle.Exclamation, "حقل إجباري")
txtID.Focus()
Exit Sub
End If
If txtpassword.Text = "" Then
MsgBox("لابد من ادخال كلمة السر", MsgBoxStyle.Exclamation, "جقل إجباري")
txtpassword.Focus()
Exit Sub
End If
Try
Dim str As String = "select ID,userPassword from Users where ID='" & txtID.Text & "' and userPassword='" & txtpassword.Text & "'"
Dim sda As New SqlDataAdapter(str, Class1.sqlcon)
Dim ds As New DataSet
sda.Fill(ds)
If ds.Tables(0).Rows.Count > 0 Then
Me.Hide()
frmMain.Show()
Else
MsgBox("خطأ في البيانات المدخلة", MsgBoxStyle.Critical, "خطأ")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End class
when ever i want to connect it to table login gives me this message
((((cannot open database employes requested by the login the login failed login failed for user 'Toshiba-PC\Toshiba'.))))))))