I can not figure out how to add a new row to the sql table.

private void button1_Click(object sender, EventArgs e) { testLinqDataContext db = new testLinqDataContext(); IEnumerable<customer> data = from customer in db.customers select customer; // выбор всего из таблицы клиентов dataGridView1.DataSource = data; // покажи в гриде string name = textBox1.Text; string lastname = textBox2.Text; if(name != null && lastname != null) { //занести в бд } } 
  • To understand at least something, show the testLinqDataContext - Bulson

1 answer 1

I understand that the code should look like this somewhere:

  if(name != null && lastname != null) { customer newCustomer = new Customer(); //не знаю как поля называются в Вашем классе, //но я думаю, что Вы поймете суть newCustomer.name = name; newCustomer.lastname = lastname; ... db.customers.Add(newCustomer); db.SubmitChanges(); }