Jump to content

Problem with update in ADO.NET

- - - - -

  • Please log in to reply
1 reply to this topic

#1
Abbath1349

Abbath1349

    Newbie

  • Members
  • PipPip
  • 22 posts
I have two stored procedure ShowMyProducts to enter data to table DataGridView and ShowByName for search product. I've written code for change table but it's does't work.
Update code:

SqlCommand cmd = new SqlCommand("ShowByName", cn);

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add("@Product_name", SqlDbType.NVarChar, 35);

            cmd.Parameters["@Product_name"].Value = "Сыр";

            dAdapt.UpdateCommand = cmd;

            dAdapt.Update(Table_1, "MyProducts");

           // dataGridView1.DataSource = Table_1.Tables["MyProducts"];


All code:

SqlConnection cn = new SqlConnection("Data Source=microsof-1346c9;" +

         "Integrated Security=SSPI; Initial Catalog=Товары");

        DataSet Table_1; SqlDataAdapter dAdapt;

        public Form1()

        {

            InitializeComponent();

            Table_1 = new DataSet("Products");

            dAdapt = new SqlDataAdapter("ShowMyProducts", cn);

            dAdapt.Fill(Table_1, "MyProducts");

          //  DataTable MyTab = new DataTable();

            dataGridView1.DataSource=Table_1.Tables["MyProducts"];

        }

        private void button1_Click(object sender, EventArgs e)

        {

            SqlCommand cmd = new SqlCommand("ShowByName", cn);

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add("@Product_name", SqlDbType.NVarChar, 35);

            cmd.Parameters["@Product_name"].Value = "Сыр";

            dAdapt.UpdateCommand = cmd;

            dAdapt.Update(Table_1, "MyProducts");

           // dataGridView1.DataSource = Table_1.Tables["MyProducts"];

         }



#2
sam_coder

sam_coder

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 372 posts
I assume no exceptions are being thrown. Try using the Profiler.

Also, try this for parameters,
instead of this:
cmd.Parameters.Add("@Product_name", SqlDbType.NVarChar, 35);

            cmd.Parameters["@Product_name"].Value = "Сыр";

Try this:
cmd.Parameters.AddWithValue("@Product_name", "Сыр")


But yea, any more indications as to what exactly the problem is, might help with a better diagnosis




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users