TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
keshav singh
NA
550
261k
how can i dynamically bind the datagridview with database
Nov 19 2009 1:57 AM
i have feeding form which has four fields name,lastname,category,occupation in info table in database
when i run the program first time the data is show in gridview control
but when i fill the all fields and click on insert button. the data is inserted successfully but it does not show the new inserted data in datagridview control.
can you tell me the code for this
on form load
public Form1()
{
InitializeComponent();
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from info",con);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
con.Close();
}
on insert button click
private void button1_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("insert into info values('"+textBox1.Text+"','"+textBox2.Text+"','"+textBox3.Text+"','"+textBox4.Text+"')",con);
cmd.ExecuteNonQuery();
con.Close();
lblmsg.Text = "Data inserted Succesfully";
dataGridView1.datasource= infodatasource
}
thanks in advance
keshav
Reply
Answers (
1
)
how to avoid a leave event after it is called
TextBox problem with newLine