1,105,242 Community Members

inserting data into database through datagrid

Member Avatar
A.Muqeetkhan
Newbie Poster
3 posts since Sep 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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);
Member Avatar
Ancient Dragon
Achieved Level 70
27,573 posts since Aug 2005
Reputation Points: 5,231 [?]
Q&As Helped to Solve: 3,028 [?]
Skill Endorsements: 115 [?]
Team Colleague
Featured
Sponsor
 
1
 

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.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: