[龟鱼派 (比目鱼先生)]:VB中的未处理的“System.Data.SqlClient.SqlException”类型的异常出现在 system.data.dll 中。是怎么回事

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/28 00:32:35
Dim strsql As String
If TextBox1.Text <> "" Then
strsql = "xm like'" & TextBox1.Text & "'and"
End If
If TextBox2.Text <> "" Then
strsql = strsql & "xb like'" & TextBox2.Text & "' and "
End If
Dim ds As New DataSet
Dim con As New SqlConnection
Dim ade As New SqlDataAdapter
Dim com As New SqlCommand
con.ConnectionString = "server=.;database=txl;uid=sa;pwd="
con.Open()
com.Connection = con
com.CommandText = "select * from dhb where " & strsql
ade.SelectCommand = com
ade.Fill(ds)
con.Close()
DataGrid1.DataSource = ds.Tables(0)
到底错在那里啊?

那是关于数据库的错误异常。
原因很多可能,看你的代码好像是数据库连接失败造成的。
改成
con.ConnectionString = "server=(local);database=txl;uid=sa;pwd="
试试
由于原因很多我也不能确定这是正确的方法

不知所云~~~~