首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

未处理的System.InvalidOperationException类型的异常出现在 system.data.dll 中

2014-01-28 
Dim con As New SqlClient.SqlConnection con.ConnectionString server192.168.27.125databasetiaoma

Dim con As New SqlClient.SqlConnection
con.ConnectionString = "server=192.168.27.125;database=tiaoma;uid=sa;pwd=; "
con.Open()

Dim cmd As New SqlClient.SqlCommand
cmd.CommandText = "select Count(*) from " + dd + " where tiaoma= ' " + tiaoma + " ',con "
Dim count As Integer
count = Convert.ToInt32(cmd.ExecuteScalar())
If (count > 0) Then
con.Close()
Else
cmd.CommandText = "Insert into " + dd + " values( ' " + time + " ', ' " + tiaoma + " ', ' " + mc + " ', ' " + bb + " ', ' " + line + " ') "
cmd.ExecuteNonQuery()
con.Close()
End If

----------------------------------------------
未处理的System.InvalidOperationException类型的异常出现在 system.data.dll 中

其他信息: ExecuteReader: Connection 属性尚未初始化。
{count = Convert.ToInt32(cmd.ExecuteScalar()}这一行错误!!!

------解决方法--------------------------------------------------------
select Count(*) from " + dd + " where tiaoma= ' " + tiaoma + " ',con
后面的 ",con "要去掉

 

        

热点排行