Subject: Error in displaying datagrid
Posted By: lamort Post Date: 12/1/2006 12:02:26 PM
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


Go to topic 52186

Return to index page 105
Return to index page 104
Return to index page 103
Return to index page 102
Return to index page 101
Return to index page 100
Return to index page 99
Return to index page 98
Return to index page 97
Return to index page 96