473,397 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Item Searching in Database in not there

Hi! pls help me.
i already have my project. its on VB.net and MS SQL server.

but im having a hard time in trapping if the one im searching in the databse is not there..

im searching a primary key but if not there im having an error.

pls help me. heres my code for viewing.



Public Function GetByRefNum(ByVal RefNum As Integer) As DataSet
'' This is where we are inserted all the values
Dim connectionString As String = "Data Source=MLTimo;Initial Catalog=OSDSdb;Persist Security Info=True;User ID=sa; PWD=password"
Dim myConnection As SqlConnection = New SqlConnection(connectionString)

Dim myDataSet As New DataSet
Dim myDataAdapter As SqlDataAdapter

Try

Dim cmd As New SqlCommand
'Dim reader As SqlDataReader

cmd.CommandText = "SELECT * FROM tblRequest Where RefNumber = " + RefNum.ToString()
cmd.CommandType = CommandType.Text
cmd.Connection = myConnection

myConnection.Open()
myDataAdapter = New SqlDataAdapter(cmd)
'' fill the dataset
myDataAdapter.Fill(myDataSet)

Catch ex As Exception
Throw ex
Finally
'' close the connection
myConnection.Close()
End Try

Return myDataSet

End Function



'the error will come here. "Index out of range something"

Dim ds As DataSet = GetByRefNum(RequestForm.TxBxRefNum.Text)
Me.LblRefNum.Text = ds.Tables(0).Rows(0).Item("RefNumber").ToString()
Me.LblType.Text = ds.Tables(0).Rows(0).Item("Type").ToString()
Me.LblRequestor.Text = ds.Tables(0).Rows(0).Item("Requestor").ToString()
Me.LblName.Text = ds.Tables(0).Rows(0).Item("Name").ToString()
Me.LblVenue.Text = ds.Tables(0).Rows(0).Item("Venue").ToString()
Me.LblStat.Text = ds.Tables(0).Rows(0).Item("Status").ToString()
Oct 30 '11 #1
0 812

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Lloyd Stevens | last post by:
Is there a way to peform a query search on a database where you type in a word to be searched across multiple fields? a bit like a search engine if you like. for example if searching a stock...
0
by: Hrvoje Voda | last post by:
How to save only checked items from checkedListBox to database, through dataSet. Hrcko
3
by: jayender.vs | last post by:
Hi, I am doing a menu in asp.net here is the sample code for that: <asp:Menu ID="Menu1" runat="server" Orientation="Horizontal" > <Items>
3
by: bobby | last post by:
Hi there. I have a simple Access database with names and numbers. I'm trying to add another entry through vb6 but i get a SYNTAX ERROR in INSERT INTO statement. Please help. What am i doing...
20
by: fniles | last post by:
I am using VB.NET 2003, SQL 2000, and SqlDataReader. As I read data from tblA, I want to populate tblB. I use SQLDataReader for both tables. I do not use thread. When I ExecuteReader on tblB, I...
76
MMcCarthy
by: MMcCarthy | last post by:
Normalisation is the term used to describe how you break a file down into tables to create a database. There are 3 or 4 major steps involved known as 1NF (First Normal Form), 2NF (Second Normal...
0
MMcCarthy
by: MMcCarthy | last post by:
There is a question in the Access forum you may be able to help with. I can move it over here if it is appropriate. http://www.thescripts.com/forum/thread598513.html Could you also check out...
5
by: =?Utf-8?B?Y2RiaWdncw==?= | last post by:
Hi, I've been tasked to write a windows app that allows people to enter transactions. For each transaction, there can be an unknown number of items, and as a person enters an item, the program...
2
by: thomson | last post by:
Hi All, i have a sit which deals with cars, and i have a table associated with this, i do have a problem in designing the application, i have lot of places in the web page where it hits the the...
3
deepuv04
by: deepuv04 | last post by:
Hi, I have a table Users with the columns say UserName FirstName LastName City State Province Zip Country
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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,...
0
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...

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.