Good day. I fill datatabla with values ​​from base. datatabl I fill with values ​​from 2 tables (I use the joint request). Datatable later changes, and these changes can not be made to the database. Errors in the process of the program does not occur, just the database is not updated. Please tell me what the problem is. Filling datatable data

sqlConnection = New SqlClient.SqlConnection("Data Source = *; User id = *; Password = *; database=* ;Integrated Security = False;") sqlConnection.Open() commandStrEmployee = "SEL ECT e.id_correspondent, e.surname, d.title,d.id_duty fr om Employee e inner join Duty d on e.id_duty=d.id_duty" adapterEmployee = New SqlDataAdapter(commandStrEmployee, sqlConnection) adapterEmployee.Fill(dtEmployee) 

Data entry in datatable

 Dim a As DataRow = Form1.dtEmployee.Rows(i) a.BeginEdit() a("id_duty") = Form1.dt_duty.Rows(b)("id_duty") a("title") = Form1.dt_duty.Rows(b)("title") a.EndEdit() a.AcceptChanges() 

DB Update

 Form1.adapterEmployee.Update(Form1.dtEmployee) 

For some reason, the last line does not work.

  • Format the code - wind

1 answer 1

Did a similar program on C # with entering into the database from the textbox. The code is similar to VB, I think it will help. There are engaged in the database 2 fields discipline and publishing.

string discipline = Convert.ToString (comboBox1.Text); string publishing = Convert.ToString (textBox6.Text);

  cls.Conn.Open(); SqlCommand iCommand = cls.Conn.CreateCommand(); iCommand.CommandText = "INSERT INTO " + "Books (Дисциплины, 

Publisher) "+" VALUES (@discipline, @publishing) ";

  iCommand.Parameters.Add("@discipline", 

SqlDbType.NChar, 100); iCommand.Parameters ["@ discipline"]. Value = discipline;

  iCommand.Parameters.Add("@publishing", 

SqlDbType.NChar, 30); iCommand.Parameters ["@ publishing"]. Value = publishing;

In this case, cls is the main class of the application, and Conn is the database connection variable. They are described as:

static public SqlConnection Conn;

Although you can omit the last item. In your case, it will be easier to make the entry of the database fields into a variable and put them in the database in a separate thread, as shown by me.