ช่วยดูให้หน่อยคะ ว่าต้องทำไรอีกไม่ไม่ได้คะ
คือเขียน vb.net โปรแกรมบน Emu pocket เพื่อให้ติดต่อฐานข้อมูล sql server น่ะคะ เริ่มจาก select ธรรมดาๆ แต่มันก็ไม่ขึ้นน่ะคะ ช่วยๆกันดูให้หน่อยนะคะ ว่าผิดพลาดตรงไหน หรือต้องมีการเพิ่มเติม เซตอะไรตรงไหนอีก ขอคำแนะนำด้วยคะ Form code: Imports System.Data Imports System.Data.SqlClient
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim strsql As String Dim tmpDataTable As New DataTable strsql = "SELECT * FROM Employees " tmpDataTable =CreateDataSet(strsql,"t_test").Tables("t_test") If tmpDataTable.Rows.Count > 0 Then Me.DataGrid1.DataSource = tmpDataTable
End If
Modglobal code : Imports System.Data.SqlClient Public strconn As String = "server =SUWANNAS-REIMRR;packet size=4096;user id=sa;password=1234;data source=SUWANNAS-REIMRR;persist security info=False;initial catalog=Northwind"
Public Function CreateDataSet(ByVal StrSql As String, ByVal TableName As String) As DataSet Dim DataAd As New SqlDataAdapter Dim DataDS As DataSet = New DataSet Dim strconn As String = "server =SUWANNAS-REIMRR;packet size=4096;user id=sa;password=1234;data source=SUWANNAS-REIMRR;persist security info=False;initial catalog=Northwind" Dim DataConn As SqlConnection = New SqlConnection(strconn) Dim sqlCommand = New SqlCommand(StrSql, DataConn)
Try DataAd = New SqlDataAdapter(StrSql, DataConn) DataAd.Fill(DataDS, TableName) DataAd = Nothing Catch ex As Exception MsgBox(ex.Message) Return Nothing End Try
If IsNothing(DataDS) Then Return Nothing End If Return DataDS End Function End Module
พอรันดูแล้วมันขึ้นว่า
A managed NullReferenceException Occurred at Application: : Run+0x1a Application: : Run + 0xd
Ok to terminate
รบกวนทุกๆคนด้วยคะ
|