none
Getting error as " Incorrect syntax near '.' " while binding the datas to grid view .... RRS feed

  • Question


  • Hi ....

    I am getting error as  " Incorrect syntax near '.' "   in the line da.fill(ds,mytable) ." while binding the datas in gridview ...
    In SQL server database i am having a table name as mytable with column name Product name as below.

    Product name

    analges
    sargosis
    noni
    deralit
    miben

    I am also having a table for each product name in sql server .
    For Product name analges the table analges is :

    Incident no  Product name   Login id   Service Type   Priority  Major     status    
     mel002         analges      Param       Incident        low     no        open
     gav345         analges      suresh      Request         high    yes       closed
     hlo678         analges      ram         Request         low     no        open
     
    and etc...

    so there are seperate tables for other Product names also (sargosis,noni etc) with the same column names as analges table with different datas ..

    I am having a grid view ,list box in asp.net page ...and the codes in it is as follows:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;
    using System.Data.SqlClient;

    namespace WebApplication1mynew
    {
        public partial class _Default : System.Web.UI.Page
        {
            string[] table = new string[100];
            protected void Page_Load(object sender, EventArgs e)
            {
                gettables();
                getdata();

            }
            public void gettables()
            {
                SqlConnection con = new SqlConnection("Data Source=ydc233;Initial Catalog=fwr;Integrated Security=True");
                con.Open();
                DataSet ds = new DataSet();
                string com="select * from mytable ";
                SqlDataAdapter da=new SqlDataAdapter (com,con);
                da.Fill (ds,"table");
                ListBox1 .DataSource =ds;
                ListBox1 .DataBind ();
                int count = ListBox1.Items.Count;
               
                for (int i = 0; i < count; i++)
                {
                    table[i] = ListBox1.Items[i].ToString();
                }
            }

            public void getdata()
            {
                SqlConnection con = new SqlConnection("Data Source=ydc233;Initial Catalog=fwr;Integrated Security=True");
                con.Open();
                DataSet ds = new DataSet();
                string st=null ;
                string com = "SELECT mytable[0].[Incident no], mytable[0].[Product Name] , mytable[0].[Login id], mytable[0].Status FROM mytable[0] WHERE mytable[0] .[Service Type] = 'Incident'" + st + " order by [Product Name]";
                for (int i = 1; i < table .Count(); i++)
                {
                    st = "UNION SELECT mytable[i].[Incident no], mytable[i].[Product Name], mytable[i].[Login id] , mytable[i] .Status  FROM mytable[i]  WHERE mytable[i].[Service Type] = 'Incident'";
                }
              
                SqlDataAdapter da = new SqlDataAdapter(com, con);
                da.Fill(ds, "mytable");
                GridView1.DataSource = ds;
                GridView1.DataBind();
             }
         }
    }


    Can any one please clear it and give the solution ....

     

     

    Monday, January 2, 2012 9:31 AM

Answers

All replies

  • Hi mathina,

    Welcome to MSDN Forum.

    Based on the issue, I think it probably caused by the wrong T-SQL. I suggest you to add watch window to check the T-SQL it created, or copy and paste it in your sql server, try to run it to check whether it is correct.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us
    Wednesday, January 4, 2012 2:35 AM
    Moderator
  • Thank you sir ,

    I found that the query is wrong ...

    • Marked as answer by mathina Wednesday, January 4, 2012 2:08 PM
    Wednesday, January 4, 2012 2:08 PM
  • Thank you sir ,

    I found that the query is wrong ...


    mathina,

    Great to see you've located your issue.  Perhaps now is a good time to consider making some changes to the design?  I know that I've seen a huge benefit to both development and maintenance when I removed all of the T-SQL out of the application and moved it to the database in Stored Procedures. 


    James Crandall ~ http://javitechnologies.com Spatial Database Solutions
    Wednesday, January 4, 2012 6:14 PM