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. Database & SysAdmin
  3. Database
  4. Filling a dataset not working

Filling a dataset not working

Scheduled Pinned Locked Moved Database
databasegraphicssysadminsecurityhelp
5 Posts 3 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.
  • B Offline
    B Offline
    Blekk
    wrote on last edited by
    #1

    Hi, I need a little help. I have created an untyped dataset on my form called dataSet1 and am trying to create a parent/child relationship with a datagrid displaying the data. But I am getting a weird exception on the code:

    da.Fill(dataSet1);

    The exception says: "Incorrect syntax near '*'" I don't understand this exception atall. Please help me, Any reply is appreciated. P.S. here is the full code:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.SqlClient;

    namespace NorthwindTest
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }

        private void Form1\_Load(object sender, EventArgs e)
        {
            string strConnect = @"server = (local)\\SQLEXPRESS; integrated security = sspi; database = C:\\SQL\\NORTHWND.MDF";
            string strQuery1 = @"SELECT \* FROM employees";
            string strQuery2 = @"SELECT \* FROM orders";
            string strQuery = strQuery1 + strQuery2;
    
    
            SqlConnection conn = new SqlConnection(strConnect);
            SqlDataAdapter da = new SqlDataAdapter(strQuery, conn);
            da.TableMappings.Add("Table", "employees");
            da.TableMappings.Add("Table1", "orders");
            da.Fill(dataSet1);
            DataRelation relation = new DataRelation("employeeorders", dataSet1.Tables\[0\].Columns\["employeeid"\], dataSet1.Tables\[1\].Columns\["employeeid"\]);
            dataSet1.Relations.Add(relation);
            dataGridView1.DataBindings.Add("datasouce", dataSet1, "employees");
        }
    
    
    }
    

    }

    R S 2 Replies Last reply
    0
    • B Blekk

      Hi, I need a little help. I have created an untyped dataset on my form called dataSet1 and am trying to create a parent/child relationship with a datagrid displaying the data. But I am getting a weird exception on the code:

      da.Fill(dataSet1);

      The exception says: "Incorrect syntax near '*'" I don't understand this exception atall. Please help me, Any reply is appreciated. P.S. here is the full code:

      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.Data;
      using System.Drawing;
      using System.Text;
      using System.Windows.Forms;
      using System.Data.SqlClient;

      namespace NorthwindTest
      {
      public partial class Form1 : Form
      {
      public Form1()
      {
      InitializeComponent();
      }

          private void Form1\_Load(object sender, EventArgs e)
          {
              string strConnect = @"server = (local)\\SQLEXPRESS; integrated security = sspi; database = C:\\SQL\\NORTHWND.MDF";
              string strQuery1 = @"SELECT \* FROM employees";
              string strQuery2 = @"SELECT \* FROM orders";
              string strQuery = strQuery1 + strQuery2;
      
      
              SqlConnection conn = new SqlConnection(strConnect);
              SqlDataAdapter da = new SqlDataAdapter(strQuery, conn);
              da.TableMappings.Add("Table", "employees");
              da.TableMappings.Add("Table1", "orders");
              da.Fill(dataSet1);
              DataRelation relation = new DataRelation("employeeorders", dataSet1.Tables\[0\].Columns\["employeeid"\], dataSet1.Tables\[1\].Columns\["employeeid"\]);
              dataSet1.Relations.Add(relation);
              dataGridView1.DataBindings.Add("datasouce", dataSet1, "employees");
          }
      
      
      }
      

      }

      R Offline
      R Offline
      Rocky
      wrote on last edited by
      #2

      Well I'd rather use a typed dataset for this. Its makes it alot easier for u And dont combine both queries in one string. Just makea typed dataset and then just fill both tables with the TableAdapter.Fill method and add the relation to teh DatagridView hope it helps Rocky

      B 1 Reply Last reply
      0
      • R Rocky

        Well I'd rather use a typed dataset for this. Its makes it alot easier for u And dont combine both queries in one string. Just makea typed dataset and then just fill both tables with the TableAdapter.Fill method and add the relation to teh DatagridView hope it helps Rocky

        B Offline
        B Offline
        Blekk
        wrote on last edited by
        #3

        Ok thanks, I'll try this, but I'm just a beginner at ADO.NET so I may come back here for help if I have misunderstood what you mean.

        R 1 Reply Last reply
        0
        • B Blekk

          Ok thanks, I'll try this, but I'm just a beginner at ADO.NET so I may come back here for help if I have misunderstood what you mean.

          R Offline
          R Offline
          Rocky
          wrote on last edited by
          #4

          ok surething :)

          1 Reply Last reply
          0
          • B Blekk

            Hi, I need a little help. I have created an untyped dataset on my form called dataSet1 and am trying to create a parent/child relationship with a datagrid displaying the data. But I am getting a weird exception on the code:

            da.Fill(dataSet1);

            The exception says: "Incorrect syntax near '*'" I don't understand this exception atall. Please help me, Any reply is appreciated. P.S. here is the full code:

            using System;
            using System.Collections.Generic;
            using System.ComponentModel;
            using System.Data;
            using System.Drawing;
            using System.Text;
            using System.Windows.Forms;
            using System.Data.SqlClient;

            namespace NorthwindTest
            {
            public partial class Form1 : Form
            {
            public Form1()
            {
            InitializeComponent();
            }

                private void Form1\_Load(object sender, EventArgs e)
                {
                    string strConnect = @"server = (local)\\SQLEXPRESS; integrated security = sspi; database = C:\\SQL\\NORTHWND.MDF";
                    string strQuery1 = @"SELECT \* FROM employees";
                    string strQuery2 = @"SELECT \* FROM orders";
                    string strQuery = strQuery1 + strQuery2;
            
            
                    SqlConnection conn = new SqlConnection(strConnect);
                    SqlDataAdapter da = new SqlDataAdapter(strQuery, conn);
                    da.TableMappings.Add("Table", "employees");
                    da.TableMappings.Add("Table1", "orders");
                    da.Fill(dataSet1);
                    DataRelation relation = new DataRelation("employeeorders", dataSet1.Tables\[0\].Columns\["employeeid"\], dataSet1.Tables\[1\].Columns\["employeeid"\]);
                    dataSet1.Relations.Add(relation);
                    dataGridView1.DataBindings.Add("datasouce", dataSet1, "employees");
                }
            
            
            }
            

            }

            S Offline
            S Offline
            Sushant Duggal
            wrote on last edited by
            #5

            **string strConnect = @"server = (local)\SQLEXPRESS; integrated security = sspi; database = C:\SQL\NORTHWND.MDF"; string strQuery1 = @"SELECT * FROM employees"; string strQuery2 = @"SELECT * FROM orders"; string strQuery = strQuery1 + strQuery2; SqlConnection conn = new SqlConnection(strConnect); SqlDataAdapter da = new SqlDataAdapter(strQuery, conn); **When you add the strings : strQuery = strQuery1 + strQuery2; here the strQuery becomes: "SELECT * FROM employeesSELECT * FROM orders" and you can see this is an invalid query , so it results in error. Regards,

            Sushant Duggal.****

            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