Home All Groups Group Topic Archive Search About

Error in displaying data grid

Author
1 Dec 2006 5:05 PM
Death
Hi all

I am having some trouble on displaying datagrid data from my database

Below is the code sample :

<%@ Page Language="VB" Debug ="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<script language ="VBSCRIPT" runat="server">
Sub Page_Load(Src As Object, e As EventArgs)
        Dim myConnection As SqlConnection
        Dim DBCommand As SqlDataAdapter
        Dim DSPagedata As New DataSet

        myConnection = New _
        SqlConnection("server=localhost;uid=sa;pwd=;" _
        & "database=test1")

        Dim QueryString As String = "select * from User"

        DBCommand = New SqlDataAdapter(QueryString, _
        myConnection)
        DBCommand.Fill(DSPagedata,
"User")----------------------------------------------error line

        MyDataGrid.DataSource = DSPagedata.Tables("User")
        MyDataGrid.DataBind()
    End Sub
</script>

<html><body>
<h3><font face="Verdana">
Simple Select to a DataGrid Control.
</font></h3>
<ASP:DataGrid id="MyDataGrid" runat="server"
Width="700"
BackColor="#ccccff"
BorderColor="black"
ShowFooter="false"
CellPadding=3
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
MaintainState="false"
/>
</body></html>



The error is when calling the DBCommand . It show incorrect syntax near
User. But User is the table in my server. Did i do anything wrong?
Pls advice .Thanks

Author
1 Dec 2006 5:37 PM
Ken Tucker [MVP]
Try

Select * from [User]

Ken
-------------------------

Show quoteHide quote
"Death" wrote:

> Hi all
>
> I am having some trouble on displaying datagrid data from my database
>
> Below is the code sample :
>
> <%@ Page Language="VB" Debug ="true" %>
> <%@ Import Namespace="System.Data" %>
> <%@ Import Namespace="System.Data.SqlClient" %>
>
> <script language ="VBSCRIPT" runat="server">
> Sub Page_Load(Src As Object, e As EventArgs)
>         Dim myConnection As SqlConnection
>         Dim DBCommand As SqlDataAdapter
>         Dim DSPagedata As New DataSet
>
>         myConnection = New _
>         SqlConnection("server=localhost;uid=sa;pwd=;" _
>         & "database=test1")
>
>         Dim QueryString As String = "select * from User"
>
>         DBCommand = New SqlDataAdapter(QueryString, _
>         myConnection)
>         DBCommand.Fill(DSPagedata,
> "User")----------------------------------------------error line
>
>         MyDataGrid.DataSource = DSPagedata.Tables("User")
>         MyDataGrid.DataBind()
>     End Sub
> </script>
>
> <html><body>
> <h3><font face="Verdana">
> Simple Select to a DataGrid Control.
> </font></h3>
> <ASP:DataGrid id="MyDataGrid" runat="server"
> Width="700"
> BackColor="#ccccff"
> BorderColor="black"
>  ShowFooter="false"
> CellPadding=3
> CellSpacing="0"
> Font-Name="Verdana"
> Font-Size="8pt"
> HeaderStyle-BackColor="#aaaadd"
> MaintainState="false"
> />
> </body></html>
>
>
>
> The error is when calling the DBCommand . It show incorrect syntax near
> User. But User is the table in my server. Did i do anything wrong?
> Pls advice .Thanks
>
>
Author
2 Dec 2006 1:06 AM
Death
Yup can already

Thanks for the help.

Ken wrote:
Show quoteHide quote
> Try
>
> Select * from [User]
>
> Ken
> -------------------------
>
> "Death" wrote:
>
> > Hi all
> >
> > I am having some trouble on displaying datagrid data from my database
> >
> > Below is the code sample :
> >
> > <%@ Page Language="VB" Debug ="true" %>
> > <%@ Import Namespace="System.Data" %>
> > <%@ Import Namespace="System.Data.SqlClient" %>
> >
> > <script language ="VBSCRIPT" runat="server">
> > Sub Page_Load(Src As Object, e As EventArgs)
> >         Dim myConnection As SqlConnection
> >         Dim DBCommand As SqlDataAdapter
> >         Dim DSPagedata As New DataSet
> >
> >         myConnection = New _
> >         SqlConnection("server=localhost;uid=sa;pwd=;" _
> >         & "database=test1")
> >
> >         Dim QueryString As String = "select * from User"
> >
> >         DBCommand = New SqlDataAdapter(QueryString, _
> >         myConnection)
> >         DBCommand.Fill(DSPagedata,
> > "User")----------------------------------------------error line
> >
> >         MyDataGrid.DataSource = DSPagedata.Tables("User")
> >         MyDataGrid.DataBind()
> >     End Sub
> > </script>
> >
> > <html><body>
> > <h3><font face="Verdana">
> > Simple Select to a DataGrid Control.
> > </font></h3>
> > <ASP:DataGrid id="MyDataGrid" runat="server"
> > Width="700"
> > BackColor="#ccccff"
> > BorderColor="black"
> >  ShowFooter="false"
> > CellPadding=3
> > CellSpacing="0"
> > Font-Name="Verdana"
> > Font-Size="8pt"
> > HeaderStyle-BackColor="#aaaadd"
> > MaintainState="false"
> > />
> > </body></html>
> >
> >
> >
> > The error is when calling the DBCommand . It show incorrect syntax near
> > User. But User is the table in my server. Did i do anything wrong?
> > Pls advice .Thanks
> >
> >