Imports System.Data
Imports System.Data.SqlServerCe
Imports System.Data.SqlTypes
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms
Public Class frmHome
Private Sub frmHome_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
BindDataGrid()
End Sub
Private Sub BindDataGrid()
Dim myConnection As SqlCeConnection
Dim dt As New DataTable
Dim Adapter As SqlCeDataAdapter
myConnection = New SqlCeConnection("Data Source =" _
+ (System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly.GetName.CodeBase ) + "\AppDatabase1.sdf;"))
myConnection.Open()
Dim myCommand As SqlCeCommand = myConnection.CreateCommand()
myCommand.CommandText = "SELECT [id], [name], [email] FROM [mytable]"
myCommand.CommandType = CommandType.Text
Adapter = New SqlCeDataAdapter(myCommand)
Adapter.Fill(dt)
myConnection.Close()
ขอบคุณมากค๊าาบ!!!!
Tag : .NET, Ms SQL Server 2008, Device (Mobile), VB.NET, VS 2008 (.NET 3.x)
หลักเลย ก็ Data Souce ครับ แล้วก็ ตรง imports ครับ แก้เป็น System.Data.SqlClient
Dim myConnection As SqlCeConnection แก้เป็น Dim myConnection As SqlConnection
Dim Adapter As SqlCeDataAdapter แก้เป็น Dim Adapter As SqlDataAdapter
Dim myCommand As SqlCeCommand แก้เป็น Dim myCommand As SqlCommand
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlServerCe
Imports System.Data.SqlTypes
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms
Public Class frmHome
' By https://www.thaicreate.com (mr.win)'
Private Sub frmHome_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
BindDataGrid()
End Sub
Private Sub BindDataGrid()
Dim dt As New DataTable
Dim Adapter As SqlDataAdapter
Dim myConnection As New SqlClient.SqlConnection
Dim strConnString As String
strConnString = "Data Source=10.9.3.36;Initial Catalog=AIP_DATABASE;Persist Security Info=True;User ID=sa;Password=xxx"
myConnection.ConnectionString = strConnString
myConnection.Open()
Dim myCommand As SqlCommand = myConnection.CreateCommand()
myCommand.CommandText = "SELECT [id], [name], [email] FROM [mytable]"
myCommand.CommandType = CommandType.Text
Adapter = New SqlDataAdapter(myCommand)
Adapter.Fill(dt)
myConnection.Close()
ผมแก้แล้ว แต่พอ Complie ใส่ตัว Emalator ที่ผมตั้ง IP ให้เป็น 10.9.6.113 ( ใช้ PC Ping เจอเลยคิดว่าน่าจะติดต่อ Database Server ได้)