473,503 Members | 10,322 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What is wrong with the following code?

2 New Member
Hi,

Below is the code snippet where i would like to display a msgbox if there are no matching records. I always get a NullReferenceException at iRows = ds.Tables("dt").Rows.Count

Please help me solve it
Thanks

Try
Dim sql As String = "Select * from property where accountno = " & id.ToString '& "%'"
Dim sa As MySqlDataAdapter = New MySqlDataAdapter
sa.SelectCommand = New MySqlCommand(sql, conn)
Dim ds As New DataSet
Dim dt As DataTable = New DataTable("property")
Dim iRows As Integer = New Integer


Try

dt.Columns.Add("accountno")
ds.Tables.Add(dt)
iRows = ds.Tables("dt").Rows.Count
MsgBox(iRows, , "Number of datarows: iRows")
'test the value of iRow
If iRows > 0 Then
'No datarows present
Else
'at least one datarow present
End If
Aug 12 '10 #1
2 1094
MrMancunian
569 Recognized Expert Contributor
iRows = ds.Tables("dt").Rows.Count refers to a datatable you called "dt", but you only created a DataTable called "property".

Steven
Aug 12 '10 #2
Kavya Rao
2 New Member
Thanks a lot :)
Aug 12 '10 #3

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

Similar topics

1
2780
by: Marlon | last post by:
<! -- Web.config--> <authentication mode="Windows" /> <identity impersonate="true" /> <! -- Web.config--> where Configurations.ADsUsersPath is...
3
1797
by: Razvan | last post by:
Hi! What is wrong with the following code ? // Test1.cpp : Defines the entry point for the console application. //
3
2836
by: Materialised | last post by:
I am having some issues with the following code, basically what I am trying to do, is familierise myself with compiler warnings, when I try to access a private or protected class function. Here is...
0
908
by: Just Me | last post by:
What's wrong with the following code? The TempName read is valid since I just wrote it and also did a QuickWatch to check it. But once I set the PrinterName the count of papersizes goes to zero. ...
4
1443
by: -D- | last post by:
I'm new to .net and just learning c#. I have the following code in vb and want to convert this to c# Public Class PositionData Private strText As String Private strUrl As String Public...
7
1790
by: Jason Kid | last post by:
Hi, Please tell me what's wrong with the following code. private bool CheckIt( int iArg, bool fArg) { bool fIsGood = false;
15
2502
by: kenneth | last post by:
I was trying to use multiple thread to optimize my following code, but met some problems, anyone can help me? k are initialized. int computePot() { int i, j; for( i=0; i<500; i++ ) { for(...
2
2092
by: SRT | last post by:
Hi, I have the following code below, which works if I do the following Call No1 'Call No2 Exit Sub For whatever reason it fails at Me!.SetFocus at the end of Sub No2 with
6
1947
by: CSharper | last post by:
I have following code, if you cut and paste it in VS and compile it you see only an answer of 0. I was expecting values from o through 2999 using System; using System.Collections.Generic;...
3
7313
by: muddasirmunir | last post by:
I am trying to give the following Icon in my form in vb6. http://www.mediafire.com/?ymzgkgyi50j But , when I put this in my form I got error "Invalid Picutre" What wrong in it? How to add...
0
7207
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
7095
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
7294
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
7361
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
7015
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
7470
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...
1
5026
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
3173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
403
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.