Query returns nothing

B

Bijoy Naick

I am new to asp.net and having some trouble with a page.. First, here is
the code.. The script section goes in the head. The body contains the
datagrid line..

<script language="vb" runat="server">
Sub Page_Load(Source as Object, E As EventArgs)
Dim myConnection as SqlConnection
Dim myCommand as SqlCommand
Dim myReader as SqlDataReader
Dim sql as String
Dim connStr as String

sql = "SELECT * FROM Shippers"

connStr="server=localhost;uid=dotNetUser;pwd=myPasswd;database=Northwind
"

myConnection = New SqlConnection(connStr)
myConnection.Open()

myCommand = New SqlCommand(sql, myConnection)
myReader = myCommand.ExecuteReader()

theList.DataSource = myReader
theList.DataBind()
End Sub

followed by

<asp:DataGrid ID="theList" runat="server"/>

My problem is that when the code executes, the datagrid is empty. There
are no error messages. I knwo for a fact that the Shippers table
contains a few records. The dotNetUser account exits in SQL Server and
has owner privs on the Northwind database..

What am i doing wrong?
 
O

ONIL@

Hi, Bijoy !
Try this, could work!

a) Establish your solution configurations to debug
b) set a debug point in the sql = "SELECT * FROM Shippers"
b) debug your code since this point and thats it! (I know this sound like a
joke but believe me, it works..)

Greetings.
ONil@.
MX.
 
P

Prince

I believe the DataGrig control will not render unless
you've bound some columns to it.

ex.

<asp:DataGrid ID="shoppingCartDataGrid" Runat="server"
DataKeyField="ID">

<Columns>
<asp:BoundColumn DataField="ProductName"
HeaderText="Product Name"></asp:BoundColumn>
</Columns>

</asp:DataGrid>

That should work.

-- Prince
 

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,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top