Click here to Skip to main content
15,793,452 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello guys,
I have this code which does:
Automatically updates changes in datagridview
I need it to:
As I don't have column named "akce" in datagridview I need it to automatically insert to every new row value from zakce.Text to column "akce" in sql table.

Is there any way to do that? I tried the code which is now commented but it creates new row instead adding this to new row in datagridview.

C#
da = new SqlDataAdapter("select * from zajsluz WHERE akce="+zakce.Text, spojeni);
                //SqlCommand a = new SqlCommand("INSERT INTO zajsluz(akce)values(@akce)");
                //a.Parameters.AddWithValue("@akce", zakce.Text);
                sqlCommandBuilder = new SqlCommandBuilder(da);
                dt = new DataTable();
                da.Fill(dt);
                dtg_sluzby.DataSource = dt;

and this is my code on update btton:
C#
public void btn_uloz_sl_Click(object sender, EventArgs e)
        {
            try
            {
                da.Update(dt);
                MessageBox.Show("Služby byly editovány!");
            }
            catch (Exception se)
            {
                MessageBox.Show(se.Message);
            }
 
        }
Posted

1 solution

Have a look here: Automatically fill column in datagridview with default value[^]. There you'll find an aswer ;)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900