| มือใหม่หัดใช้ -- connect database ไม่ได้ 
                                      สร้างฟอร์มขึ้นมาโดยจะให้ดึงข้อมูลจาก microsoft sql server 2005มาโชว์ที่ datagridview (vb.net 2008) ทำแบบ pocket pc นะคะ
 
 ใช้โค๊ดแบบนี้ (ไม่รุว่าถูกหรือเปล่านะค่ะ ไม่มั่นใจเลย)
 
 Public Shared strConn As String = \"Data Source=.\\SQLEXPRESS;Initial Catalog=Purchase2-2;User ID=user11;Password=1234\"
 
 แล้วไม่ทราบว่าต้องประกาศตัวแปรอะไรไว้ข้างบนก่อนมั้ย
 
 Dim conn As New SqlConnection(strConn)
 conn.Open()
 Dim myCom As New SqlCommand
 myCom.CommandText = \"Select * from Branch\"
 myCom.CommandType = CommandType.Text
 myCom.Connection = conn
 
 Dim dr As SqlDataReader
 dr = myCom.ExecuteReader
 
 
 If dr.HasRows = True Then
 Dim dt As New DataTable
 dt.Load(dr)
 DataGridView1.DataSource = dt
 Else
 MessageBox.Show(\"ไม่พบข้อมูล\")
 End If
 
 conn.Close()
 
 
 
 End Sub
 
 มันจะ
 error ตรง sql.......... หมดเลยค่ะ
 
 งง มาก หรือว่า ทำไม่ถูกก็ไม่รู้
 
 รอผู้รู้มาตอบด้วยนะค่ะ จะขอบพระคุณมากค่ะ
 |