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 "要去掉