Click here to Skip to main content
15,795,581 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
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();
                dtg_sluzby.DataSource = dt;

and this is my code on update btton:

public void btn_uloz_sl_Click(object sender, EventArgs e)
             MessageBox.Show("Služby byly editovány!");
         catch (Exception se)


Thanks in advance

1 solution

did akce column in sql table is integer or text

if it integer 
"select * from zajsluz WHERE akce= "+convert.toint16(zakce.text);

if it text
"select * from zajsluz WHERE akce= '"+zakce.text +"'";
Share this answer
maneavnash 12-Jul-13 8:33am    
plase show me your insert query for akce column....

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