 |
|
ขอถามเรื่องการเขียนโปรแกรมเชื่อมต่อระหว่าง Smart Device กับ SQL Server 2008 |
|
 |
|
|
 |
 |
|
จากบทความ
.NET Smart Device เขียนโปรแกรมบน Smartphone, Pocket PC , Windows CE , Window Mobile 5-6, Hand Held,...
https://www.thaicreate.com/dotnet/dotnet-smartdevice-smartphone-pocket-pc-windows-ce.html
ถ้าผมต้องการเปลี่ยนจาก Database Server CE เป็น SQL Server ผมต้องแก้ตรงไหนบ้างครับ ช่วยแนะนำหน่อย
ยกตัวอย่าง Code นี้ก็ได้ครับ
Code (VB.NET)
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)
|
|
 |
 |
 |
 |
Date :
2012-05-15 09:56:02 |
By :
activewin |
View :
3404 |
Reply :
11 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
หลักเลย ก็ 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
|
 |
 |
 |
 |
Date :
2012-05-15 10:24:09 |
By :
kanchen |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แก้ตรง Connection String ด้วยครับ ก็ได้แล้ว
|
 |
 |
 |
 |
Date :
2012-05-15 10:52:40 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
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 ได้)
ผมปรากฏว่า มันขึ้น Code Error ตามนี้ครับ

รบกวนช่วยด้วยครับ..
|
ประวัติการแก้ไข 2012-05-17 08:12:00
 |
 |
 |
 |
Date :
2012-05-16 08:55:01 |
By :
activewin |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
HELP ME PLEASEEE!!!!! 
ช่วยด้วยคร๊าาาบบบ!!!
|
 |
 |
 |
 |
Date :
2012-05-17 10:52:52 |
By :
activewin |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เข้าใจว่ามันน่าจะได้เฉพาะ SQL CE น่ะครับ
|
 |
 |
 |
 |
Date :
2012-05-17 13:09:00 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ครับ
สงสัยจะไม่ได้ จริงๆ
ขอบคุณครับ

|
 |
 |
 |
 |
Date :
2012-05-17 17:07:58 |
By :
activewin |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่เคยเขียนเหมือนกัน แต่เอาใจช่วยนะครับ From : iiiBBB
|
 |
 |
 |
 |
Date :
2012-05-17 19:35:06 |
By :
panyapol |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองหันไปใช้พวก Web Service แทนครับ สะดวกดีครับ 
|
 |
 |
 |
 |
Date :
2012-05-17 20:14:04 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ที่จริงแล้ว Smart Device นั้นสามารถ Connect กับ SQL Server ได้อยู่แล้วครับ แต่ที่ตกม้าตายอยู่บ่อยๆ นั้นเพราะ
ตัว Virtual Smart Device ที่ทดสอบด้วย Visual Studio นั้นไม่ได้ทำการ เชื่อมต่อกับ Network ภายนอกไว้ครับก็เลย
ทำให้ Connect ไม่ได้ ยังไงลองเช็คดูก่อนนะครับ
|
 |
 |
 |
 |
Date :
2012-05-19 18:03:14 |
By :
smeproject |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เปลี่ยนภาษาใน Database จาก Thai_CI_AS เป็น Latin1_General_100_CI_AI ครับ
|
 |
 |
 |
 |
Date :
2013-01-28 20:48:20 |
By :
ping8252 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองหันมาให้ Web Service แทนดีกว่าครับ
|
 |
 |
 |
 |
Date :
2018-06-15 14:30:54 |
By :
pommy |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|