1

我正在创建一个 vb.net 应用程序,其中出现错误“我不知道如何解决此错误,并且表中有 4 个字段,'System.Data.SqlClient.SqlException'发生了第一次机会异常类型System.Data.dll"

  1. o_id 主键自动递增 1
  2. c_id静止的
  3. 所有者名称varchar()
  4. 投资

    Dim connetionString As String
    
    Dim cnn As SqlConnection
    
    Dim cmd As New SqlCommand
    
    
    connetionString = "Data Source=.\SQLEXPRESS;AttachDbFilename='C:\Users\javed\Documents\Visual Studio 2008\Projects\WindowsApplication1\WindowsApplication1\bin\Debug\Database1.mdf';Integrated Security=True;User Instance=True"
    
    cnn = New SqlConnection(connetionString)
    
    Try
    
        cnn.Open()
        MsgBox("Connection is Open ! ")
        cmd.Connection = cnn
        cmd.CommandText = "INSERT INTO owner_detail(c_id, o_name, investment) values(@cid,'" + TextBox1.Text + "','" + TextBox2.Text + "')"
        cmd.ExecuteNonQuery()
        MsgBox("Data is Successfully Inserted! ")
        cnn.Close()
    
    Catch ex As Exception
    
        MsgBox("Can not open connection ! ")
    
    End Try
    
4

1 回答 1

4

您没有在任何地方添加参数@cid。

cmd.Parameters.Add(new SqlParameter("@cid", SqlDbType.Int))
cmd.Parameters("@cid").Value = Idvalue
于 2012-11-12T10:25:56.350 回答