'Imports System.Data.SqlClientDim con As New SqlClient.SqlConnection Dim strCon As String = "Data Source=SERVERNAME;Initial Catalog=DATABASENAME;Integrated Security=SSPI;Connection Timeout=10;" 'NT Authentication 'For SQL Authentication Dim strCon As String = "Data Source=SERVERNAME;Initial Catalog=DATABASENAME;User ID=USERNAME;Password=PASSWORD;Connection Timeout=50;" Dim strCommand As String = "SELECT * FROM TABLE" Dim command As SqlCommand Dim da As SqlDataAdapter Dim dt As New DataTable Try con.ConnectionString = strCon command = New SqlCommand(strCommand, con) command.CommandTimeout = 3000
da = New SqlDataAdapter(command) da.Fill(dt) MsgBox(dt.Rows.Count.ToString())
'FOR INSERT, UPDATE, DELETE, USE BELOW
'Dim count as Integer = command.ExecuteNonQuery()
'count is the affected row number
Catch ex As Exception MessageBox.Show(ex.Message, "Error") Finally If con.State = ConnectionState.Open Then con.Close() End If End Try
Friday, May 24, 2013
VB.NET ile SQL Server'a Bağlanmak.
VB.NET ile SQL Server'a bağlanmak ve sorgu sonucunu datatable'a atmak.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment