当我运行程序时,在(cmd.executenonquery)上获取错误

时间:2018-12-12 05:10:57

标签: vb.net

insertAfter

1 个答案:

答案 0 :(得分:1)

尝试一下……

Using sqlcon As New SqlConnection(strCaseConnString)    
                sbSql.Append("insert into CandTable(Passport_No,Name,[Father Name],[Mother Name],Date_of_Birth) values(@Passport_No,@Name,@FatherName,@MotherName,@Date_of_Birth")    
                Using sqlCmd As New SqlCommand(sbSql.ToString(), sqlcon)
                    sqlCmd.Parameters.Add("@Passport_No", SqlDbType.NVarChar).Value = Candi.TxtPass.Text
                    sqlCmd.Parameters.Add("@Name", SqlDbType.NVarChar).Value = Candi.TxtName.Text
                    sqlCmd.Parameters.Add("@FatherName", SqlDbType.NVarChar).Value =  Candi.TxtFather.Text
                    sqlCmd.Parameters.Add("@MotherName", SqlDbType.NVarChar).Value = Candi.TxtMother.Text
                    sqlCmd.Parameters.Add("@Date_of_Birth", SqlDbType.NVarChar).Value = Candi.TxtDob.Text
                    sqlcon.Open()
                    sqlCmd.ExecuteNonQuery()
                    sqlcon.Close()
                End Using    
            End Using