Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. SQLCommandBuilder problem

SQLCommandBuilder problem

Scheduled Pinned Locked Moved C#
helpdatabasesql-serversysadminsecurity
3 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    HolyGrandFather
    wrote on last edited by
    #1

    Hi,, i'm workin for 15 hours till now on that tiny piece of code, and i just can't get it right... in my application i have DAL a class with all the Database functions.. my problem is when i want to update the sql server with a dataset.. when ever i use the automated SQLDATAADAPTER wizard , it's ok.. but i want it to be through the code.. I know that if i want to use the DataAdapter.Update(Dataset) i need to implement the UpdateCommand,DeleteCommand ,SelectCommand and insertCommand. And i also know the SqlCommandBuilder can generate those sqlcommands automatically. but when i try doin SQLDataAdapter.UpdateCommand = SqlCommandBuilder.GetUpdateCommand(); i get the followin error. ExecuteReader: CommandText property has not been initialized Please Help .. i'm STUCK! i'm postin my DAL as well... Thanks! public class DAL { private SqlConnection conn; private SqlDataAdapter adapter; private SqlCommand selCommand = new SqlCommand(); private SqlCommandBuilder builder; public DAL() { conn = new SqlConnection("Server="+AppSettings.AppSets.ServerAddress+";Database=MaftehDb;Integrated Security=SSPI"); adapter = new SqlDataAdapter(); builder = new SqlCommandBuilder(adapter); selCommand.Connection = conn; adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey; adapter.SelectCommand = new SqlCommand(); adapter.SelectCommand.Connection = conn; adapter.UpdateCommand = new SqlCommand(); adapter.UpdateCommand.Connection = conn; builder.RefreshSchema(); adapter.UpdateCommand = builder.GetUpdateCommand(); adapter.InsertCommand=new SqlCommand(); adapter.InsertCommand.Connection=conn; adapter.DeleteCommand = new SqlCommand(); adapter.DeleteCommand.Connection = conn; } }

    G 1 Reply Last reply
    0
    • H HolyGrandFather

      Hi,, i'm workin for 15 hours till now on that tiny piece of code, and i just can't get it right... in my application i have DAL a class with all the Database functions.. my problem is when i want to update the sql server with a dataset.. when ever i use the automated SQLDATAADAPTER wizard , it's ok.. but i want it to be through the code.. I know that if i want to use the DataAdapter.Update(Dataset) i need to implement the UpdateCommand,DeleteCommand ,SelectCommand and insertCommand. And i also know the SqlCommandBuilder can generate those sqlcommands automatically. but when i try doin SQLDataAdapter.UpdateCommand = SqlCommandBuilder.GetUpdateCommand(); i get the followin error. ExecuteReader: CommandText property has not been initialized Please Help .. i'm STUCK! i'm postin my DAL as well... Thanks! public class DAL { private SqlConnection conn; private SqlDataAdapter adapter; private SqlCommand selCommand = new SqlCommand(); private SqlCommandBuilder builder; public DAL() { conn = new SqlConnection("Server="+AppSettings.AppSets.ServerAddress+";Database=MaftehDb;Integrated Security=SSPI"); adapter = new SqlDataAdapter(); builder = new SqlCommandBuilder(adapter); selCommand.Connection = conn; adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey; adapter.SelectCommand = new SqlCommand(); adapter.SelectCommand.Connection = conn; adapter.UpdateCommand = new SqlCommand(); adapter.UpdateCommand.Connection = conn; builder.RefreshSchema(); adapter.UpdateCommand = builder.GetUpdateCommand(); adapter.InsertCommand=new SqlCommand(); adapter.InsertCommand.Connection=conn; adapter.DeleteCommand = new SqlCommand(); adapter.DeleteCommand.Connection = conn; } }

      G Offline
      G Offline
      Gokulan Venattil
      wrote on last edited by
      #2

      Hii, Here the piece of code all you need. You must the same DataSet and DataAdapter for the update operation. private void UpdateData() { if (myDataSet.HasChanges()) { adapter.Update(ds.Tables[0]); myDataSet.AcceptChanges(); } } private void LoadData() { conn = new OleDbConnection(ConnectionString); conn.Open(); selCommand = new OleDbCommand("SELECT * FROM EMP",conn); adapter = new OleDbDataAdapter(selCommand); builder = new OleDbCommandBuilder(adapter); myDataSet = new DataSet(); adapter.Fill(myDataSet); dataGrid1.DataSource = myDataSet.Tables[0]; } You can pass the OleDbDataAdapter,DataSet to your DAL method. Regards, Gokulan

      H 1 Reply Last reply
      0
      • G Gokulan Venattil

        Hii, Here the piece of code all you need. You must the same DataSet and DataAdapter for the update operation. private void UpdateData() { if (myDataSet.HasChanges()) { adapter.Update(ds.Tables[0]); myDataSet.AcceptChanges(); } } private void LoadData() { conn = new OleDbConnection(ConnectionString); conn.Open(); selCommand = new OleDbCommand("SELECT * FROM EMP",conn); adapter = new OleDbDataAdapter(selCommand); builder = new OleDbCommandBuilder(adapter); myDataSet = new DataSet(); adapter.Fill(myDataSet); dataGrid1.DataSource = myDataSet.Tables[0]; } You can pass the OleDbDataAdapter,DataSet to your DAL method. Regards, Gokulan

        H Offline
        H Offline
        HolyGrandFather
        wrote on last edited by
        #3

        Thankd! i was going out of my mind... the thing the tackeld me was when i did the Update , i gave him only the Dataset where you wrote me to give him the dataset.table[0] , it solved my prob! AnyWAy ! THANKS!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups