We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,313 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

inserting data into database through datagrid

guys i need ur help i want to insert data directly into the sql table using c# here is my code all that i have been able to do is get the values from the table not insert them i tried to do it this way but apprently there is some thing wrong with this code plz help me out

string sConnectionString = "Data Source=localhost;Initial Catalog=ScratchCardSystem2;Integrated Security=True;pooling=true";
                SqlConnection objConn = new SqlConnection(sConnectionString);
                objConn.Open();

                string query = "SELECT * FROM store_adj_note_detail_1";
                SqlDataAdapter dAdapter = new SqlDataAdapter(query,objConn);

                SqlCommandBuilder cBuilder = new SqlCommandBuilder(dAdapter);
                DataTable dTable = new DataTable();
                //fill the DataTable
                dAdapter.Fill(dTable);

                //the DataGridView
                DataGridView dgView = new DataGridView();

                //BindingSource to sync DataTable and DataGridView
                BindingSource bSource = new BindingSource();

                //set the BindingSource DataSource
                bSource.DataSource = dTable;

                //set the DataGridView DataSource
                dgView.DataSource = bSource;
                dAdapter.Update(dTable);
2
Contributors
1
Reply
12 Hours
Discussion Span
3 Months Ago
Last Updated
4
Views
A.Muqeetkhan
Newbie Poster
3 posts since Sep 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Here is a good tutorial, it's written in vb.net but its almost identical to C# because they both use .NET framework classes and namespaces.

Ancient Dragon
Achieved Level 70
Team Colleague
32,145 posts since Aug 2005
Reputation Points: 5,836
Solved Threads: 2,577
Skill Endorsements: 69

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.1079 seconds using 2.69MB