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
  1. Home
  2. General Programming
  3. C#
  4. updating database

updating database

Scheduled Pinned Locked Moved C#
databasetutorialannouncement
4 Posts 2 Posters 0 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.
  • N Offline
    N Offline
    Nitin raj
    wrote on last edited by
    #1

    hi, I have fetched two database tables "MTQABenchMarks" and "Users" in the datagridview. This is a windows application. Now I have to update the "MTQABenchMark" database after making changes to the datatable present in the application. When I run the code it is throwing an exception "Dynamic SQL generation is not supported against multiple base tables." How to solve this. the code is public Form1() { InitializeComponent(); } static SqlConnection Con = new SqlConnection("Data Source= 192.168.100.234; Initial Catalog=gishyd; User ID=sa; password=gis*2005"); SqlDataAdapter Da = new SqlDataAdapter("SELECT dbo.Users.UserID, dbo.MTQABenchMark.Id as EmpID, dbo.Users.FirstName + ' ' + dbo.Users.LastName AS Name, dbo.MTQABenchMark.NoofMinPerDay,dbo.MTQABenchMark.PerMonth FROM dbo.Users INNER JOIN dbo.MTQABenchMark ON dbo.Users.UserID = dbo.MTQABenchMark.EID ", Con); DataSet Ds = new DataSet(); private void Form1_Load(object sender, EventArgs e) { Da.Fill(Ds, "MTQABenchMark"); dataGridView1.DataSource = Ds.Tables["MTQABenchMark"]; } private void button2_Click(object sender, EventArgs e) { SqlCommandBuilder CmdBld = new SqlCommandBuilder(Da); Da.InsertCommand = CmdBld.GetInsertCommand(); Da.Update(Ds, "MTQABenchMark"); MessageBox.Show(" Database is Updated"); } } }

    Nitin Raj Bidkikar

    A 1 Reply Last reply
    0
    • N Nitin raj

      hi, I have fetched two database tables "MTQABenchMarks" and "Users" in the datagridview. This is a windows application. Now I have to update the "MTQABenchMark" database after making changes to the datatable present in the application. When I run the code it is throwing an exception "Dynamic SQL generation is not supported against multiple base tables." How to solve this. the code is public Form1() { InitializeComponent(); } static SqlConnection Con = new SqlConnection("Data Source= 192.168.100.234; Initial Catalog=gishyd; User ID=sa; password=gis*2005"); SqlDataAdapter Da = new SqlDataAdapter("SELECT dbo.Users.UserID, dbo.MTQABenchMark.Id as EmpID, dbo.Users.FirstName + ' ' + dbo.Users.LastName AS Name, dbo.MTQABenchMark.NoofMinPerDay,dbo.MTQABenchMark.PerMonth FROM dbo.Users INNER JOIN dbo.MTQABenchMark ON dbo.Users.UserID = dbo.MTQABenchMark.EID ", Con); DataSet Ds = new DataSet(); private void Form1_Load(object sender, EventArgs e) { Da.Fill(Ds, "MTQABenchMark"); dataGridView1.DataSource = Ds.Tables["MTQABenchMark"]; } private void button2_Click(object sender, EventArgs e) { SqlCommandBuilder CmdBld = new SqlCommandBuilder(Da); Da.InsertCommand = CmdBld.GetInsertCommand(); Da.Update(Ds, "MTQABenchMark"); MessageBox.Show(" Database is Updated"); } } }

      Nitin Raj Bidkikar

      A Offline
      A Offline
      Andrei Ungureanu
      wrote on last edited by
      #2

      Select query can be run against multiple tables, while Update query can be run only one table. In your application you select data from 2 tables, and store it in a dataset. When you try to update the database you use the same dataset. It's not possible, because the application tries to update 2 tables at the same time. You should do a separate update for each table, with values from your dataset. Hope it helps.

      I will use Google before asking dumb questions

      N 1 Reply Last reply
      0
      • A Andrei Ungureanu

        Select query can be run against multiple tables, while Update query can be run only one table. In your application you select data from 2 tables, and store it in a dataset. When you try to update the database you use the same dataset. It's not possible, because the application tries to update 2 tables at the same time. You should do a separate update for each table, with values from your dataset. Hope it helps.

        I will use Google before asking dumb questions

        N Offline
        N Offline
        Nitin raj
        wrote on last edited by
        #3

        how do you suggest to do that

        Nitin Raj Bidkikar

        A 1 Reply Last reply
        0
        • N Nitin raj

          how do you suggest to do that

          Nitin Raj Bidkikar

          A Offline
          A Offline
          Andrei Ungureanu
          wrote on last edited by
          #4

          Split the dataset into 2 datasets or datatables that contain fields from only one table, and then use these to update the database.

          I will use Google before asking dumb questions

          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