Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 1st, 2006, 01:03 PM
Registered User
 
Join Date: Dec 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Error in displaying data grid

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>
Simple Select to a DataGrid Control.
</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

 
Old December 1st, 2006, 01:14 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

User is probably a reserved word in the database. Try wrapping it in [] characters, like this:

select * from [User]

Or better yet, rename the table.

Cheers,
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old December 1st, 2006, 08:55 PM
Registered User
 
Join Date: Dec 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the help

Never thought that User would be a reserved word in the database

Now it works . Thank you so much.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Grid Not Displaying Error Message rojiin ASP.NET 2.0 Basics 0 October 22nd, 2007 05:13 AM
Export data from data grid to excel pomoc VB.NET 2002/2003 Basics 0 December 16th, 2005 03:11 PM
Export data from data grid to Excel pomoc Visual Basic 2005 Basics 0 December 16th, 2005 02:56 PM
trying to load db data into data grid itsajourney Beginning VB 6 2 June 7th, 2005 12:05 PM
Trouble displaying Data Grid control bam1934 ASP.NET 1.0 and 1.1 Basics 4 May 25th, 2005 07:59 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.