none
DML operation in Dataset, RRS feed

  • Question

  • hi,

     

     i am new to .net area. i meet one problem from last two days.

     

     i stored the DB information in my dataset by using adapter.fill(dataset).  after that i like to take the data from dataset by using only DML.

      i searched in google, i got only, it is possible. i tried many times still i m not get any idea about that. if u know please share with me...

     

    problem is how to connect to that dataset.  i m using oledb driver.

     if u know that connection string pls send it asap.

     

    i currently using "Provider=SQLOLEDB; server=(local);integrated security=SSPI; database=northwind"

    but i m got exception in connection.open();

     

     

    Regards,

    Karthikeyan S

    Friday, January 30, 2009 9:03 AM

Answers

  • Not exactly what error you get or what you are trying to do.

    But this example will connect to SQL Server, fill a dataset, insert a row, update a row in the Shipper table in Northwind using SQLOLEDB (SQLNCLI in this case).

            static void Main(string[] args)  
            {  
                String cs = String.Format(@"Provider=SQLNCLI;Data Source=<YOUR SERVER>;Initial Catalog=Northwind;Integrated Security=SSPI;");  
                using (OleDbConnection con = new OleDbConnection(cs))  
                {  
                    OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM Shippers", con);  
                    DataSet ds = new DataSet("ShipperDataSet");  
                    da.Fill(ds);  
     
                    // Create Update and Insert commands  
                    OleDbCommandBuilder cmdBuilder = new OleDbCommandBuilder(da);  
                    da.UpdateCommand = cmdBuilder.GetUpdateCommand();  
                    da.InsertCommand = cmdBuilder.GetInsertCommand();  
     
                    // Insert row  
                    DataRow newRow = ds.Tables[0].NewRow();  
                    newRow["ShipperID"] = 100;  
                    newRow["CompanyName"] = "NewCompany";  
                    newRow["Phone"] = "123456789";  
                    ds.Tables[0].Rows.Add(newRow);  
     
                    // Update row  
                    ds.Tables[0].Rows[0][1] = "Changed CompanyName";  
                    // Update database using Dataset via DataAdapter  
                    da.Update(ds);  
                }  
            } 

     

    HTH

    Michael

    --------------------------------------------------------------------------------

    This posting is provided "AS IS" with no warranties, and confers no rights.

    Friday, January 30, 2009 4:04 PM

All replies

  • Not exactly what error you get or what you are trying to do.

    But this example will connect to SQL Server, fill a dataset, insert a row, update a row in the Shipper table in Northwind using SQLOLEDB (SQLNCLI in this case).

            static void Main(string[] args)  
            {  
                String cs = String.Format(@"Provider=SQLNCLI;Data Source=<YOUR SERVER>;Initial Catalog=Northwind;Integrated Security=SSPI;");  
                using (OleDbConnection con = new OleDbConnection(cs))  
                {  
                    OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM Shippers", con);  
                    DataSet ds = new DataSet("ShipperDataSet");  
                    da.Fill(ds);  
     
                    // Create Update and Insert commands  
                    OleDbCommandBuilder cmdBuilder = new OleDbCommandBuilder(da);  
                    da.UpdateCommand = cmdBuilder.GetUpdateCommand();  
                    da.InsertCommand = cmdBuilder.GetInsertCommand();  
     
                    // Insert row  
                    DataRow newRow = ds.Tables[0].NewRow();  
                    newRow["ShipperID"] = 100;  
                    newRow["CompanyName"] = "NewCompany";  
                    newRow["Phone"] = "123456789";  
                    ds.Tables[0].Rows.Add(newRow);  
     
                    // Update row  
                    ds.Tables[0].Rows[0][1] = "Changed CompanyName";  
                    // Update database using Dataset via DataAdapter  
                    da.Update(ds);  
                }  
            } 

     

    HTH

    Michael

    --------------------------------------------------------------------------------

    This posting is provided "AS IS" with no warranties, and confers no rights.

    Friday, January 30, 2009 4:04 PM
  • hi,

     Finally i got the idea about the linq.

    linq is support the dml operation in the dataset.

    so friends if u needs dml operation in dataset  use the linq

    if u face the problem mail me
    Friday, February 6, 2009 12:35 PM