0

how to retrive values from database into a table using vb.net??????
I tried but i don't have either output??????
How to do this???
and my code is:

<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<% @Import Namespace="System.Data" %>
<% @Import Namespace="System.Data.SqlClient" %>
<script runat="server">
sub Page_Load()
       Dim con As New SqlConnection
Dim cmd As New SqlCommand

 con.ConnectionString = "Data Source=IMMANUEL-PC\SQLEXPRESS; Initial Catalog=dbkarthi; UID=test; PWD=test1;" 
 con.Open()
 cmd.Connection = con
 cmd.CommandText = "select * from det"
 Dim lrd As SqlDataReader = cmd.ExecuteReader()
End sub         

</script>
<form runat="server">
<asp:Repeater id="customers" runat="server">

<HeaderTemplate>
<table border="1" width="100%">
<tr bgcolor="#b0c4de">
<th>ID</th>
<th>Name</th>
<th>Address</th>
<th>Age</th>
<th>Gender</th>
</tr>
</HeaderTemplate>

<ItemTemplate>
<tr bgcolor="#f0f0f0">
<td><%#DataBinder.Eval(Container.DataItem, "id")%> </td>
<td><%#DataBinder.Eval(Container.DataItem, "name")%> </td>
<td><%#DataBinder.Eval(Container.DataItem, "address")%> </td>
<td><%#DataBinder.Eval(Container.DataItem, "age")%> </td>
<td><%#DataBinder.Eval(Container.DataItem, "gender")%> </td>

</tr>
</ItemTemplate>

<FooterTemplate>
</table>
</FooterTemplate>

</asp:Repeater>
</form>
</body>
</html>

Edited by Reverend Jim: wrong forum

2
Contributors
5
Replies
33
Views
4 Years
Discussion Span
Last Post by ammukarthi
0

i just want to display the output in the table thats why i created a table using html...

0

is it going to be displayed on a browser? If not then just use VB.NET's built-in grid control. In any event. read the chapter about databases in that tutorial

Edited by Ancient Dragon

0

I got the output and the corrected code is:

<% @Import Namespace="System.Data" %>
<% @Import Namespace="System.Data.SqlClient" %>
<script runat="server">
sub Page_Load()
       Dim con As New SqlConnection
Dim cmd As New SqlCommand

 con.ConnectionString = ///my connection string///
 con.Open()
 cmd.Connection = con
 cmd.CommandText = "select * from det"
 customers.DataSource = cmd.ExecuteReader() 
 customers.DataBind()
End sub         

</script>
<form runat="server">
<asp:Repeater id="customers" runat="server">

<HeaderTemplate>
<table border="1" width="100%">
<tr bgcolor="#b0c4de">
<th>ID</th>
<th>Name</th>
<th>Address</th>
<th>Age</th>
<th>Gender</th>
</tr>
</HeaderTemplate>

<ItemTemplate>
<tr bgcolor="#f0f0f0">
<td><%#DataBinder.Eval(Container.DataItem, "id")%> </td>
<td><%#DataBinder.Eval(Container.DataItem, "name")%> </td>
<td><%#DataBinder.Eval(Container.DataItem, "address")%> </td>
<td><%#DataBinder.Eval(Container.DataItem, "age")%> </td>
<td><%#DataBinder.Eval(Container.DataItem, "gender")%> </td>

</tr>
</ItemTemplate>

<FooterTemplate>
</table>
</FooterTemplate>

</asp:Repeater>
</form>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.