恋雨v😲 可爱的恋雨1
关注数: 14 粉丝数: 25 发帖数: 658 关注贴吧数: 41
求大佬帮助 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; using System.Threading.Tasks; using System.Configuration; using System.Xml; using System.Xml.Linq; using System.Data.Linq; using System.Collections; namespace Systems { public partial class TJSJ : Form { string strCon = "Data Source=(local);Database=Systems;uid=sa;pwd=123456;"; DataClasses1DataContext Linq; public TJSJ() { InitializeComponent(); } private void label2_Click(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { Linq = new DataClasses1DataContext(strCon); Information employee = new Information(); employee.ID = textBox1.Text; employee.Name = textBox2.Text; employee.Type = comboBox1.Text; employee.Price = textBox3.Text; employee.Number = textBox4.Text; Linq.Information.InsertOnSubmit(employee); Linq.SubmitChanges(); MessageBox.Show("数据添加成功"); Bindlnfo(); } private void Bindlnfo() { Linq = new DataClasses1DataContext(strCon); var result = from info in Linq.Information select new { 商品编号=info.ID, 商品名称=info.Name, 商品类型=info.Type, 商品价格=info.Price, 商品数量=info.Number }; dataGridView1.DataSource = result; } private void button2_Click(object sender, EventArgs e) { UsersJM form1 = new UsersJM(); form1.Show(); this.Close(); } } Linq.Information.InsertOnSubmit(employee);这一段无法运行,说Information表没有主键无法在上面执行添加。可是我的表里面是有主键的啊
1 下一页