473,473 Members | 1,614 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Row doesn't exist problem

Hi

I've written my first asp.net page below. It queries an Access database with
one table consisting of two columns - a username and a server name. The
users enter their login name and the page queries the database and then
directs them to the correct server. This works fine as long as their name
actually exists in the database. If it doesn't the the page fails at the

server = dataSet.Tables(0).Rows(0).Item(0).ToString()

line saying row doesn't exist. My question is how can I handle this? If the
usersname is not in the database I would then like the server string to be
set to a predefined value such as 'noserver'.

Cheers

Mike

Sub Page_Load()

If Page.IsPostback

Dim mailserver As String
mailserver = MyQueryMethod(txtName.Text)

Select Case mailserver
Case "Bob"
Response.Redirect("http://localhost/mailserver1")
Case "Bill"
Response.Redirect("http://localhost/mailsever2")
Case Else
Response.Redirect("http://localhost/nomailserver")
End Select

End If

End Sub

Function MyQueryMethod(ByVal user As String) As String
Dim connectionString As String =
"Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data
Source=C:\Documents an"& _
"d Settings\Mike\My Documents\BegASPNET11\Ch01\users.mdb"
Dim dbConnection As System.Data.IDbConnection = New
System.Data.OleDb.OleDbConnection(connectionString )

Dim queryString As String = "SELECT [Users].[Mailserver] FROM
[Users] WHERE ([Users].[User] = @User)"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

Dim dbParam_user As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_user.ParameterName = "@User"
dbParam_user.Value = user
dbParam_user.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_user)

Dim dataAdapter As System.Data.IDbDataAdapter = New
System.Data.OleDb.OleDbDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New System.Data.DataSet
dataAdapter.Fill(dataSet)

Dim server As String
server = dataSet.Tables(0).Rows(0).Item(0).ToString()

Return server
End Function
Nov 18 '05 #1
4 1216
"Mike" <mike@notdisclosed!!.com> wrote in
news:eT*************@TK2MSFTNGP10.phx.gbl:
Hi

I've written my first asp.net page below. It queries an Access
database with one table consisting of two columns - a username
and a server name. The users enter their login name and the page
queries the database and then directs them to the correct
server. This works fine as long as their name actually exists in
the database. If it doesn't the the page fails at the

server = dataSet.Tables(0).Rows(0).Item(0).ToString()

line saying row doesn't exist. My question is how can I handle
this? If the usersname is not in the database I would then like
the server string to be set to a predefined value such as
'noserver'.


Mike,

If dataSet.Tables(0).Rows.Count > 0 Then
Return dataSet.Tables(0).Rows(0).Item(0).ToString()
Else
Return "noserver"
End If
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 18 '05 #2
Hi Mike, you want to test if the value is null using the IsDBNull function.
Here's an example:

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
Dim ds As New DataSet
Dim dt As New DataTable
Dim server As String
ds.Tables.Add(CreateDataSource())
If IsDBNull(ds.Tables(0).Rows(0).Item(0)) Then
server = "Not in database"
Else
server = ds.Tables(0).Rows(0).Item(0).ToString()
End If
Response.Write(server)
End Sub

Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn("CurrencyValue", GetType(Double)))
dt.Columns.Add(New DataColumn("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function
Does this help?

Ken
Microsoft MVP [ASP.NET]
Toronto

"Mike" <mike@notdisclosed!!.com> wrote in message
news:eT*************@TK2MSFTNGP10.phx.gbl...
Hi

I've written my first asp.net page below. It queries an Access database
with
one table consisting of two columns - a username and a server name. The
users enter their login name and the page queries the database and then
directs them to the correct server. This works fine as long as their name
actually exists in the database. If it doesn't the the page fails at the

server = dataSet.Tables(0).Rows(0).Item(0).ToString()

line saying row doesn't exist. My question is how can I handle this? If
the
usersname is not in the database I would then like the server string to be
set to a predefined value such as 'noserver'.

Cheers

Mike

Sub Page_Load()

If Page.IsPostback

Dim mailserver As String
mailserver = MyQueryMethod(txtName.Text)

Select Case mailserver
Case "Bob"
Response.Redirect("http://localhost/mailserver1")
Case "Bill"
Response.Redirect("http://localhost/mailsever2")
Case Else
Response.Redirect("http://localhost/nomailserver")
End Select

End If

End Sub

Function MyQueryMethod(ByVal user As String) As String
Dim connectionString As String =
"Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data
Source=C:\Documents an"& _
"d Settings\Mike\My Documents\BegASPNET11\Ch01\users.mdb"
Dim dbConnection As System.Data.IDbConnection = New
System.Data.OleDb.OleDbConnection(connectionString )

Dim queryString As String = "SELECT [Users].[Mailserver] FROM
[Users] WHERE ([Users].[User] = @User)"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

Dim dbParam_user As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_user.ParameterName = "@User"
dbParam_user.Value = user
dbParam_user.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_user)

Dim dataAdapter As System.Data.IDbDataAdapter = New
System.Data.OleDb.OleDbDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New System.Data.DataSet
dataAdapter.Fill(dataSet)

Dim server As String
server = dataSet.Tables(0).Rows(0).Item(0).ToString()

Return server
End Function


Nov 18 '05 #3
Thanks Ken

"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:#w*************@tk2msftngp13.phx.gbl...
Hi Mike, you want to test if the value is null using the IsDBNull function. Here's an example:

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
Dim ds As New DataSet
Dim dt As New DataTable
Dim server As String
ds.Tables.Add(CreateDataSource())
If IsDBNull(ds.Tables(0).Rows(0).Item(0)) Then
server = "Not in database"
Else
server = ds.Tables(0).Rows(0).Item(0).ToString()
End If
Response.Write(server)
End Sub

Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn("CurrencyValue", GetType(Double)))
dt.Columns.Add(New DataColumn("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function
Does this help?

Ken
Microsoft MVP [ASP.NET]
Toronto

"Mike" <mike@notdisclosed!!.com> wrote in message
news:eT*************@TK2MSFTNGP10.phx.gbl...
Hi

I've written my first asp.net page below. It queries an Access database
with
one table consisting of two columns - a username and a server name. The
users enter their login name and the page queries the database and then
directs them to the correct server. This works fine as long as their name actually exists in the database. If it doesn't the the page fails at the

server = dataSet.Tables(0).Rows(0).Item(0).ToString()

line saying row doesn't exist. My question is how can I handle this? If
the
usersname is not in the database I would then like the server string to be set to a predefined value such as 'noserver'.

Cheers

Mike

Sub Page_Load()

If Page.IsPostback

Dim mailserver As String
mailserver = MyQueryMethod(txtName.Text)

Select Case mailserver
Case "Bob"
Response.Redirect("http://localhost/mailserver1")
Case "Bill"
Response.Redirect("http://localhost/mailsever2")
Case Else
Response.Redirect("http://localhost/nomailserver")
End Select

End If

End Sub

Function MyQueryMethod(ByVal user As String) As String
Dim connectionString As String =
"Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data
Source=C:\Documents an"& _
"d Settings\Mike\My Documents\BegASPNET11\Ch01\users.mdb"
Dim dbConnection As System.Data.IDbConnection = New
System.Data.OleDb.OleDbConnection(connectionString )

Dim queryString As String = "SELECT [Users].[Mailserver] FROM [Users] WHERE ([Users].[User] = @User)"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

Dim dbParam_user As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_user.ParameterName = "@User"
dbParam_user.Value = user
dbParam_user.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_user)

Dim dataAdapter As System.Data.IDbDataAdapter = New
System.Data.OleDb.OleDbDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New System.Data.DataSet
dataAdapter.Fill(dataSet)

Dim server As String
server = dataSet.Tables(0).Rows(0).Item(0).ToString()

Return server
End Function

Nov 18 '05 #4
Thanks Chris
"Chris R. Timmons" <crtimmons@X_NOSPAM_Xcrtimmonsinc.com> wrote in message
news:Xn**********************************@207.46.2 48.16...
"Mike" <mike@notdisclosed!!.com> wrote in
news:eT*************@TK2MSFTNGP10.phx.gbl:
Hi

I've written my first asp.net page below. It queries an Access
database with one table consisting of two columns - a username
and a server name. The users enter their login name and the page
queries the database and then directs them to the correct
server. This works fine as long as their name actually exists in
the database. If it doesn't the the page fails at the

server = dataSet.Tables(0).Rows(0).Item(0).ToString()

line saying row doesn't exist. My question is how can I handle
this? If the usersname is not in the database I would then like
the server string to be set to a predefined value such as
'noserver'.


Mike,

If dataSet.Tables(0).Rows.Count > 0 Then
Return dataSet.Tables(0).Rows(0).Item(0).ToString()
Else
Return "noserver"
End If
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/

Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Nicolas Fleury | last post by:
Hi, How can I know if a system command doesn't exist? All the ways I have tried behave like if the system command was existing but returning one. I don't want to sound provocative, but open in...
149
by: Christopher Benson-Manica | last post by:
(Followups set to comp.std.c. Apologies if the crosspost is unwelcome.) strchr() is to strrchr() as strstr() is to strrstr(), but strrstr() isn't part of the standard. Why not? --...
4
by: Rush | last post by:
If i create a new StreamReader object, based on a filename that does not exist, the SR correctly raises an exception that the file doesn't exist. Great! I love it. BUT....then SR proceeds to...
3
by: Dave Moore | last post by:
Hi All, Ok, here's my problem. I want to open a file and process its contents. However, because it is possible that the file may not exist, I also want to check whether the file() function is...
4
by: norm4h8 | last post by:
Hi everyone! I have a problem with trying to open a file in C. The following line in my code is suppoed to open a specified file if it exists and create a new one with this name if one doesn't...
1
by: H5N1 | last post by:
hi there the topic says it all. I have a outer join select statement in tableadapter that populates GridView, I want to make it updatetable, so I need to provide an update command for table...
44
by: petermichaux | last post by:
Hi, I have been using the following line of code to create an object called "Serious" if it doesn't already exist. if (Serious == null) {var Serious = {};} This works in the scripts I use...
1
by: usenet_e | last post by:
Hello, few users have problems with our application (ADP/MsAcces2000+SqlServer2000). When they want to open a report which source is a stored procedure, they get message that "record source...
1
by: sumit205 | last post by:
Error 2467:The Expression you entered refers to an object that is closed or doesn't exist . DoCmd.OpenForm frm2, WindowMode:=acDialog, OpenArgs:="c" & NewProductID In the debig mode when i...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.