我在dataset中的表里设置了主键,可是重复的信息还是可以输入
try
{
//新建DataTable
dataTable = new DataTable();
dataSet.Tables.Add(dataTable);
dataRow = dataSet.Tables["Passengers"].NewRow();
//设置DATATABLE主键
dataSet.Tables["Passengers"].PrimaryKey = new DataColumn[]
{
dataTable.Columns["passPort"]
};
//将数据插入到DataTable中
dataRow["flightCode"] = this.textBox1.Text;
dataRow["passPort"] = this.textBox3.Text;
dataRow["name"] = this.textBox2.Text;
dataRow["seatNo"] = this.textBox4.Text;
dataRow["sex"] = this.comboBox1.SelectedItem.ToString();
dataRow["age"] = Convert.ToInt32(this.textBox5.Text);
dataSet.Tables[0].Rows.Add(dataRow);
//清空TextBox
this.clearTextBox();
//自动据库更新
objCon.Open();
SqlCommandBuilder sqlCommandBuilder1 = new SqlCommandBuilder(objDataAdapter);
objDataAdapter.Update(dataSet,"passengers");
Application.DoEvents();
}
catch(Exception se)
{
MessageBox.Show(se.Message);
}
finally
{
objCon.Close();
}
这个是为什么啊??