There is a dataGridView in it the data is filled (there are also other tables that are bound by the Primary Key) while saving an error occurs. SQL Server database

and there are more warnings:

Warning 1 Field 'abc.Form1.ds' is never assigned to, and will always have its default value null 

Code:

 using (SqlConnection connection = new SqlConnection(ConnStr)) { connection.Open(); adapter = new SqlDataAdapter(sql, connection); commandBuilder = new SqlCommandBuilder(adapter); adapter.InsertCommand = new SqlCommand("sp_CreateUser", connection); adapter.InsertCommand.CommandType = CommandType.StoredProcedure; adapter.InsertCommand.Parameters.Add(new SqlParameter("@тип ппп", SqlDbType.Text, 50, "тип ппп")); adapter.InsertCommand.Parameters.Add(new SqlParameter("@тип ффф", SqlDbType.Text, 0, "тип ффф")); adapter.InsertCommand.Parameters.Add(new SqlParameter("@тип ззз", SqlDbType.Text, 50, "тип ззз")); adapter.InsertCommand.Parameters.Add(new SqlParameter("@тип ммм", SqlDbType.Text, 0, "тип ммм")); adapter.InsertCommand.Parameters.Add(new SqlParameter("@тип ккк", SqlDbType.Text, 50, "тип ккк")); adapter.InsertCommand.Parameters.Add(new SqlParameter("@тип щщщ", SqlDbType.Text, 0, "тип щщщ")); SqlParameter parameter = adapter.InsertCommand.Parameters.Add("@№ азс", SqlDbType.NChar, 10, "№ азс"); parameter.Direction = ParameterDirection.Output; adapter.Update(ds); 

Code in the header:

  public partial class Form1 : Form { DataSet ds; ... string sql = "SELECT * FROM [Азс1]"; 

enter image description here

  • one
    Do you have a place in the code where you write the value in the ds field? Type ds = new DataSet(); ? - Andrey NOP
  • Well, by default there is null, and this is an invalid argument for Update - Andrey NOP
  • Judging by your other question, you are using a DataGridView . Show the code how the data falls into this grid. After all from? Here is the same dataset and should be used. - Alexander Petrov
  • one
    Well, you declare that the ds field is declared, but you didn’t write anything to it, and that’s why it’s a mistake. - tym32167
  • @ tym32167 help fix - user298557

0