asp.net VB newbie help

liunx

Guest
i feel like a n00b right now
ne ways
i am a php developer
but client needs the project in asp.net (VB)
there are several things am stuck with
i cant finnd session_id(); in it
session_id(); in php generates some unique session id
every example on web i see mentioning
Session("someVariable")="youDesiredValue"
but i need auto generated unique value instead of "youDesiredValue"

secondly

i am getting data form mysql.....
i can write data on the page but cant use the data :(
check the code for viewing products
"preety stupid code "
<%@ Page Language="VB" AutoEventWireup="False"
EnableSessionState="true" EnableViewState="False" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Odbc" %>
<% '''''''''''''''''''Sesssion
'''''''''''''''''''''''''''Session End
%>
<%
Dim ConnStr As String = "Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=eshop;uid=root;option=3"
Dim con As OdbcConnection = New OdbcConnection(ConnStr)
Dim cmd As OdbcCommand = New OdbcCommand("select * from products where category_id=0" & Request.QueryString("cat"), con)
con.Open()
dgrAllNames.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection Or CommandBehavior.SingleResult)
dgrAllNames.DataBind()
con.Close()
con.Open()
cmd= New OdbcCommand("select * from categories", con)

dgrAllNames2.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection Or CommandBehavior.SingleResult)
dgrAllNames2.DataBind()
%>
<html>
<head>
<title>Displaying Records from MySQL 'Names' table</title>
<style>
body { font: 100% Verdana; }
</style>
</head>
<body>
header here
<p align="center">All records in the 'Names' table:</p>
<form runat="server">

<asp:DataList ID="dgrAllNames2" HorizontalAlign="Center"
CellPadding="3" Runat="server" >

<ItemTemplate>
<a href=http://www.webdeveloper.com/forum/archive/index.php/"products.aspx?cat=<%#Container.DataItem("category_id")%>"><%#Container.DataItem("name")%></a>
</ItemTemplate>
</asp:DataList>
<asp:DataList ID="dgrAllNames" HorizontalAlign="Center"
CellPadding="3" Runat="server" >

<ItemTemplate>
<a href=http://www.webdeveloper.com/forum/archive/index.php/"cart.aspx?prodid=<%#Container.DataItem("pid")%>">
<%#Container.DataItem("name")%>

<%#Container.DataItem("description")%>

<%#Container.DataItem("category_id")%>

<%#Container.DataItem("price")%>

<%#Container.DataItem("quantity")%>

<%#Container.DataItem("manf_id")%>

<%#Container.DataItem("picture")%>
</a>
</ItemTemplate>
</asp:DataList>
</form>
footer here
</body>
</html>

how can i do that if there are no rows in the result of products then display "No Products in this category"
let me know ASAP?
any one :(i feel like a n00b right now
ne ways
i am a php developer
but client needs the project in asp.net (VB)
there are several things am stuck with
i cant finnd session_id(); in it
session_id(); in php generates some unique session id
every example on web i see mentioning
Session("someVariable")="youDesiredValue"
but i need auto generated unique value instead of "youDesiredValue"

secondly

i am getting data form mysql.....
i can write data on the page but cant use the data :(
check the code for viewing products
"preety stupid code "
<%@ Page Language="VB" AutoEventWireup="False"
EnableSessionState="true" EnableViewState="False" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Odbc" %>
<% '''''''''''''''''''Sesssion
'''''''''''''''''''''''''''Session End
%>
<%
Dim ConnStr As String = "Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=eshop;uid=root;option=3"
Dim con As OdbcConnection = New OdbcConnection(ConnStr)
Dim cmd As OdbcCommand = New OdbcCommand("select * from products where category_id=0" & Request.QueryString("cat"), con)
con.Open()
dgrAllNames.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection Or CommandBehavior.SingleResult)
dgrAllNames.DataBind()
con.Close()
con.Open()
cmd= New OdbcCommand("select * from categories", con)

dgrAllNames2.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection Or CommandBehavior.SingleResult)
dgrAllNames2.DataBind()
%>
<html>
<head>
<title>Displaying Records from MySQL 'Names' table</title>
<style>
body { font: 100% Verdana; }
</style>
</head>
<body>
header here
<p align="center">All records in the 'Names' table:</p>
<form runat="server">

<asp:DataList ID="dgrAllNames2" HorizontalAlign="Center"
CellPadding="3" Runat="server" >

<ItemTemplate>
<a href=http://www.webdeveloper.com/forum/archive/index.php/"products.aspx?cat=<%#Container.DataItem("category_id")%>"><%#Container.DataItem("name")%></a>
</ItemTemplate>
</asp:DataList>
<asp:DataList ID="dgrAllNames" HorizontalAlign="Center"
CellPadding="3" Runat="server" >

<ItemTemplate>
<a href=http://www.webdeveloper.com/forum/archive/index.php/"cart.aspx?prodid=<%#Container.DataItem("pid")%>">
<%#Container.DataItem("name")%>

<%#Container.DataItem("description")%>

<%#Container.DataItem("category_id")%>

<%#Container.DataItem("price")%>

<%#Container.DataItem("quantity")%>

<%#Container.DataItem("manf_id")%>

<%#Container.DataItem("picture")%>
</a>
</ItemTemplate>
</asp:DataList>
</form>
footer here
</body>
</html>

how can i do that if there are no rows in the result of products then display "No Products in this category"
let me know ASAP


Here, this is what you do.

[your connection open, sql string..etc... here)
Dim dr as sqldatareader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
If dr.hasrows then
ddl.datasource = dr
ddl.databind()
else
ddl.Items.Add("nothing found")
End if

you will probably want to use commandbehavior.closeconnection, b/c since you are working with ddl, supposedly, once the ddl is binded, it will close the connection automatically for you. However, .net is a bit tricky on this, just do a dr.close, and then a connection.close when you are done...just to be safe.

OR, if you just want to use the data within the columsn, thsi is what you are can do,

[after you get the connection open, sql string..etc..]
Dim var1 as string
dim var2 as string
Dim dr as sqldatareader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
while dr.read()
var1 = dr(0) ' this gives you the value at the first column
var2 = dr(1) ' this gives you the value at the second column
end while

If dr(0) is an integer, do a dr.getint32 instead.... they have getint16, getFloat, getString, getDouble...etc...


not th
-Takthats exactly what i wanted to know
thanx a lot takkie
but u didnt answered about my session problem
any wayz i made my own code to generate a unique session id
thanx againthats exactly what i wanted to know
thanx a lot takkie
but u didnt answered about my session problem
any wayz i made my own code to generate a unique session id
thanx again


you can use GUID, .NET has a class (System.Guid) that allows you to generate a GUID based on certain settings.

Take a look at that class and see if it fits what you need.

- Tak
 
Back
Top