PDA

View Full Version : تو رو خدا کمکم کنید توی اتصال vb به Sql



arman 2012
یک شنبه 16 تیر 1392, 12:54 عصر
سلام
من برای اتصال Sql به vb اول یک فرم module تعریف میکنم که همه ی کانکشین هارو اونجا تعریف میکنم:

Imports System.Data
Imports System.Data.SqlClient

Module Module1
Public connectionString As String =
"Data Source=A-PC\SQL;Initial Catalog=PhoneBook;Integrated Security=True"

Public Sub SetData(ByVal sqlStr As String)
Dim mConnection As SqlConnection = New SqlConnection(connectionString)
Dim command As New SqlCommand(sqlStr, mConnection)
command.CommandType = CommandType.Text
command.CommandText = sqlStr
mConnection.Open()
Try
command.ExecuteNonQuery()
Catch myerror As SqlException
MessageBox.Show("Error Connecting to Database: " & myerror.Message)
Finally
mConnection.Close()
mConnection.Dispose()
End Try
End Sub

Public Function GetData(ByVal sqlCommand As String) As DataTable
Dim mConnection As SqlConnection = New SqlConnection(connectionString)
Dim command As New SqlCommand(sqlCommand, mConnection)
Dim adapter As SqlDataAdapter = New SqlDataAdapter()
adapter.SelectCommand = command
Dim table As New DataTable
Try
adapter.Fill(table)
Catch myerror As SqlException
MessageBox.Show("Error Connecting to Database: " & myerror.Message)
Finally
mConnection.Dispose()
End Try
Return table
End Function

End Module






حالا من یک فرم لاگین دارم
همه ی کد هایی که توی سایته خودشون کانکشین رو توی فرم تعریف میکنن
کسی یاد نداره اینجوری فرم لاگین بسازه؟؟؟
کممممممممممک:عصبانی++::عصبا ی++::عصبانی++::عصبانی++::عصبان ++:
من فرم ثبت نام رو ساختم و درست کار میکنه

systam
یک شنبه 16 تیر 1392, 16:56 عصر
سلام

برنامه رو ضمیمه کن اینطوری نمیشه نظر داد