Am developing an application with c#. I want to know how to insert data set values into the database

6 Years
Discussion Span
Last Post by Esofts

Try using SqlDataAdapter for this job.
Or you can even try using SqlComamndBuilder (of OleDb for Access database instead of Sql):

SqlDataAdapter adapter;
        DataSet dataset;
        private void Form1_Load(object sender, EventArgs e)
            SqlConnection conn = new SqlConnection(Properties.Settings.Default.Database1ConnectionString);//Set the connection to the SQL server
            adapter = new SqlDataAdapter("select * from Table1", conn); //Create a DataAdapter instance
            dataset = new DataSet();
            SqlCommandBuilder builder = new SqlCommandBuilder();//User a CommandBuilder to build insert, update automatically.
            builder.DataAdapter = adapter;

            adapter.Fill(dataset);  //Fill the DataSet
            dataGridView1.DataSource = dataset.Tables[0]; //Bind the DataSet to a DataGridView

        //You can add/remove/modify the Data in the DataGridView
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
            adapter.Update(dataset);//Update all the modification to the DataBase

I have tried all of the above of which they function to update data in the database i wanted to insert new data values to the database with DataSet

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.