In disconnected ado.net connection inserts can be made?

Answered In disconnected ado.net connection inserts can be made?

  • Friday, January 25, 2013 6:09 PM
     
     

    hi

      yesterday i read a pdf of .net downloaded from google in which it is mentioned that DataAdapter can only be used to execute select sqlcommand we cant use it for insert,update, delete....is it correct???

    but i created a sample windows application using ado disconnected architecture using dataadapter for insert and sqlcommandbuilder to store data in database...it executed successfully i didnt open and close connection

    please suggest me a correct concept..is that pdf statement is correct or wrong...

    thanks

All Replies

  • Friday, January 25, 2013 8:07 PM
     
     Answered

    What pdf document are you referring to?

    DataAdapter can be used to

    1. fill datasets using the selectcommand and then closing connection to the database. This way you have bulk data without an open connection to the DB.

    2. You can then operate on the data in the dataset in memory without having to connect to the db.

    3. When you are ready to update the data back, you can use the data adapter again, provided you have defined the update / insert / delete commands as well.

    Check the links

    http://msdn.microsoft.com/en-us/library/bh8kx08z.aspx

    and

    http://msdn.microsoft.com/en-us/library/33y2221y.aspx

    • Marked As Answer by ben den Saturday, January 26, 2013 4:22 PM
    •  
  • Saturday, January 26, 2013 5:41 PM
     
     

    hello sambeet

                           Thanks for reply

                                                   but here is a code that i wrote which is executing successful but i have doubt that if i code it in an application that could cause any issue???...the code is here

    using

    System;

    using

    System.Collections.Generic;

    using

    System.ComponentModel;

    using

    System.Data;

    using

    System.Drawing;

    using

    System.Linq;

    using

    System.Text;

    using

    System.Windows.Forms;

    using

    System.Data.SqlClient;

    namespace

    disconnect

    {

    public partial class Form1 : Form

    {

    public Form1()

    {

    InitializeComponent();

    }

    private void button1_Click(object sender, EventArgs e)

    {

    SqlConnection con = new SqlConnection("data source=.\\sqlexpress;integrated security=true;database=emp");

    SqlDataAdapter da = new SqlDataAdapter("insert into emp values(" + textBox1.Text + ",'" + textBox2.Text + "'," + textBox3.Text + ")", con);

    DataSet ds = new DataSet();

    da.Fill(ds);

    SqlCommandBuilder cbd = new SqlCommandBuilder(da);

    }

    }

    }