本文介绍了插入表格时显示错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cn As New SqlConnection("Data Source=.\INSTANCE;initial catalog=stamp;user=sa;password=gariahat")
Dim da As New SqlDataAdapter
Dim cmd As New SqlCommand
Dim ds As New DataSet
'Dim dr As SqlDataReader
cmd.Connection = cn
cn.Open()
cmd.CommandText = "insert into item(broker_id,name,bname,place,date,year,lot_no,lname,description,curr,amt) values('" & ComboBox1.Text & "', '" & TextBox1.Text & "','" & RichTextBox3.Text & "','" & TextBox2.Text & "','" & Format(CDate(TextBox3.Text), "MM/dd/yyyy") & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & RichTextBox1.Text & "','" & RichTextBox2.Text & "','" & ComboBox2.Text & "','" & TextBox8.Text & "')"
cmd.ExecuteNonQuery()
MsgBox("Data successfully added", MsgBoxStyle.Information)
Me.ItemTableAdapter.Insert(ComboBox1.Text, TextBox1.Text, RichTextBox3.Text, TextBox2.Text, TextBox3.Text, TextBox4.Text, TextBox5.Text, RichTextBox1.Text, RichTextBox2.Text, ComboBox2.Text, TextBox8.Text)
Me.ItemTableAdapter.Fill(Me.StampDataSet.item)
ComboBox1.Text = ""
ComboBox2.Text = ""
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
RichTextBox3.Text = ""
RichTextBox1.Text = ""
RichTextBox2.Text = ""
TextBox8.Text = ""
cn.Close()
显示的错误是: -
无法启用约束。一行或多行包含违反非null,唯一或外键约束的值。
错误显示在行
Me。 ItemTableAdapter.Fill(Me.StampDataSet.item)
谁能告诉我为什么会出现错误?不能理解它。
the error showing is:-
Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
the error showing in line
Me.ItemTableAdapter.Fill(Me.StampDataSet.item)
Can anyone tell me why the error is coming? cant understand it.
推荐答案
这篇关于插入表格时显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!