Click here to Skip to main content
14,767,302 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
sir i've written the code in c#:
string constr = "Data Source=TUSHAR-PC;Initial Catalog=callcenter;Persist Security Info=True;User ID=sa;Password=password@123";
    SqlConnection con = new SqlConnection(constr);
        string sql = "insert into tasks values('" + txtT_id.Text + "','" + txtname.Text + "','" + prir_txtbx.Text + "','" + stat_txtbx.Text + "','" + txtcomments.Text + "','" + dtpdue_date.Text + "','" + dtpcompletiondate + "')";
        SqlCommand cmd = new SqlCommand(sql, con);
        cmd.CommandType = CommandType.Text;
        dataGridView1.DataSource = tasksBindingSource;
    catch (Exception ex)

the data is stored in the sql server database that i have created . data is inserted to the database but the data in the datagridview is not updating.
Updated 18-Feb-13 22:44pm
Karthik Harve 19-Feb-13 3:45am
[Edit] added pre tags
Naveen.Sanagasetti 19-Feb-13 3:49am
Hi Karthik Harve , How to edit the question can you please tell me the steps..
Karthik Harve 19-Feb-13 3:54am
you can click on "Improve Question" link, that will redirect to edit screen, there you can edit the questions. Provided, you must have the privilege to edit the question, unless you are not original poster of the question.
Naveen.Sanagasetti 19-Feb-13 3:57am
this question is published by tusharkaushik , but in my screen it's not showing improve question option.
Karthik Harve 19-Feb-13 4:00am
that means, you do not have privileges to edit the question of the poster.
Naveen.Sanagasetti 19-Feb-13 4:02am
But now you can do that na..
To edit the tusharkaushik question na...
Karthik Harve 19-Feb-13 4:07am
currently, your authority points is 770, so, once it cross 1000 points, then your member level becomes silver. then you can also, edit the question.
Naveen.Sanagasetti 19-Feb-13 4:14am
Oh k k thank you , after that which option i selected for editing
Karthik Harve 19-Feb-13 4:21am
welcome. once you get that privilege, you make use of "Improve Question" link.
Naveen.Sanagasetti 19-Feb-13 4:22am
Thank's alot...
Karthik Harve 19-Feb-13 4:24am
most welcome. !!!
Surendra0x2 19-Feb-13 3:57am
Whats the Use of dataGridView1.DataSource = tasksBindingSource;
instead of Make FillDatagrid(); Method on Form Load

then Call it Anywhere to see Updated Data in Datagridview

Try this,

dataGridView1.DataSource = tasksBindingSource;
tusharkaushik 19-Feb-13 5:47am
but the method databinding() is not appeared.
what is the alternate method instead of databinding() method.
Hi. after your Save operation finished ,you must Call Window_Loaded(sender,e);
I suppose your GridView in a Window.
Good Luck

try below code.
string sql = "insert into tasks values('" + txtT_id.Text + "','" + txtname.Text + "','" + prir_txtbx.Text + "','" + stat_txtbx.Text + "','" + txtcomments.Text + "','" + dtpdue_date.Text + "','" + dtpcompletiondate + "');";

//to get the new rows.
sql += "SELECT * FROM tasks";  // replace * with column names of the table
SqlCommand cmd = new SqlCommand(sql, con);
cmd.CommandType = CommandType.Text;
DataSet _objDataSet = new DataSet();
SqlDataAdapter  _objSqlDataAdapter = new SqlDataAdapter();     
cmd.CommandText = sql;
_objSqlDataAdapter.SelectCommand = _objSQLCommand;

dataGridView1.DataSource = _objDataSet.Table[0];

hope it helps
On Form_Load Create Method FillGridview();
then call it after insert


con.close();<br />
tusharkaushik 19-Feb-13 5:49am
but i cant understand !
what should i write in the method fillgridview().
Surendra0x2 19-Feb-13 6:12am
Do like this-Bind data to Datagridview on formload
public void FillGrid()

using (SqlConnection sqlconn = new SqlConnection("server=.\\sqlexpress;database=windowform;integrated security=true"))
SqlDataAdapter da = new SqlDataAdapter("select * from reg", sqlconn);

DataSet ds = new DataSet();
dataGridView1.AutoGenerateColumns = false;

dataGridView1.DataSource = ds.Tables[0];

catch (Exception ex)



if (sqlconn.State == ConnectionState.Open)



tusharkaushik 19-Feb-13 7:10am
but i'v developed in c# windows application
Surendra0x2 20-Feb-13 6:11am
look at the coding i used dataridview which is windows tool

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

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