Error in displaying data grid

D

Death

Hi all

I am having some trouble on displaying datagrid data from my database
as i am a beginner for this
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

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>
 
M

Masudur

Death said:
Hi all

I am having some trouble on displaying datagrid data from my database
as i am a beginner for this
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

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>


Hi,

in your sqlstring u are using
select * from User
just replace with "select * from [User]"

User is a key word which return current database user..


Thanks.

Masudur
Kaz Software Ltd.
www.kaz.com.bd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,067
Latest member
HunterTere

Latest Threads

Top