来帮我看看哦??
这是我写在一个类中
'连接数据库(Sql Server)
Public Function myDBConn() As SqlConnection
myDBConn = Nothing
Try
myDBConn = New SqlConnection( "server=.;database=DX;uid=sa;pwd=001 ")
myDBConn.Open()
Return myDBConn
Catch ex As Exception
MessageBox.Show( "连接数据库失败... ", StrName, MessageBoxButtons.OK)
End Try
End Function
'用来查询判断是否存在的
Public Function myDBdt(ByVal str As String) As DataTable
myDBdt = Nothing
Dim dr As SqlDataAdapter
Try
dr = New SqlDataAdapter(str, myDBConn)
dr.Fill(myDBdt)
Return myDBdt
Catch ex As Exception
MessageBox.Show( "出错了.... ", StrName, MessageBoxButtons.OK)
End Try
End Function
在一个界面中,
DB.myDBConn()
dt = DB.myDBdt(str)
If dt.Columns.Count > 0 Then
Me.Visible = False
frmmain.ShowDialog()
Else
MessageBox.Show( "错误!!!不存在该记录 ")
End If
为什么 "dr.Fill(myDBdt) "这里出错哦..?????
[解决办法]
1