473,795 Members | 2,498 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

COMException occured while using ADODB

Hi guys,

i have a collection containing the values and metadata about a current
record.
i build it by looping through the recordset as follows:
Public Function NoNull(ByVal Value As Object) As String
Return IIf(IsDBNull(Va lue), "", Value)
End Function

Public Function LoadFields(ByRe f rs As ADODB.Recordset ) As Collection
'returns fields of a single record
Dim fldCol As Collection
Dim p As PType
Dim i As Integer
fldCol = New Collection

Try
fldCol = New Collection
With rs
For i = 0 To .Fields.Count - 1
p = New PType
p.FieldName = .Fields(i).Name
p.Datatype = .Fields(i).Type
p.varValue = NoNull(.Fields( i).Value) '*** dies
here when no value
p.intLen = .Fields(i).Defi nedSize()
fldCol.Add(p, p.FieldName)
Next i

End With

Catch e As Exception
Debug.WriteLine (e.Message)
fldCol = Nothing
End Try

Return fldCol

End Function
The above code works perfectly when i have a recordset that has both
fields and values,

but gives the following error when i have an empty recordset

error: an exception of type:
{System.Runtime .InteropService s.COMException} occurred

when i want to create a new record, i need to create an empty
collection that has the fields so i can populate then from the form
and send back to the database via a command parameters.

eg mycol = loadcollection( rs.open ("select * from mytbl where id =
-1"))

pls advise what is wrong with the code and what can i do to remedy
this?

regards

Edwinah63
Nov 20 '05 #1
4 4380
Hi Edwinah,

One of the main reasons dotnet is made is to prevent Com exceptions,
therefore you can use managed code.

That goes with in VB.net with ADONET a very fine set of methods, from which
almost everybody who have real tried it says that it is so much easier than
ADO to use.

It does not mean that the recordset is not processable in VB.net (I more and
more think that almost every classic Microsoft product is processable with
it), however ADONET fits better to VBNet. And because of that I get the idea
we more and more forget the classic methods from ADO.

Maybe it is a better idea if you try ADONET and the dataset.

I hope this helps?

Cor
Nov 20 '05 #2
Hi Cor,

thanks for your thoughts, are you saying that the error is occuring
because of bugs in the way vbnet interprets ado??

i guess the question i should have asked above was why is an exception
raised at all when trying to assign a (presumably) null value.

can you give me some equivalent adonet code???

regards

Edwinah63
Nov 20 '05 #3
Hi Edwinah,

Getting a dataset is very easy you need OleDB or Sqlclient
A connection with a connection string
www.connectionstrings.com

Create a datataadapter(S qlString, the connection)
A dataadapter with a fill
A dataset that is filled and than

And than something just as a sample, not your solution

Public Function LoadFields(ByVa l ds As Dataset) As Collection
Dim fldCol As Collection
Dim p As PType
Dim i As Integer
fldCol = New Collection
Try
fldCol = New Collection
For i = 0 To ds.tables(0).co unt - 1
dim dr as datarow = ds.tables(0).ro ws(i)
p = New PType
p.FieldName = dr.("Name")
p.Datatype = dr.("Type")
Next
End Try
Return fldCol
End Function
///

I hope this gives an idea?

Cor
Nov 20 '05 #4
Hi Cor,

thanks for your code. in light of my other problems i am having - i
may yet swap over from ado to adonet. i have to learn it anyway, so
now is probably a good time to start.

regards

Edwina
Nov 20 '05 #5

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

Similar topics

3
3756
by: Damaji Jambhale | last post by:
COMException: Catostrphic failure When I added a "dll" reference in the web project. I was able to instantiate the class OK. But when I tried to set the properties, it failed with "COMException: Catostrphic failure". Any idea? Thanks.
2
6314
by: dmiller23462 | last post by:
Hey guys, I'm back again....I've got the results displaying that I wanted but instead of having a "next" or "previous" link displayed I am getting the error msg below (I actually get the data that I'm supposed to get meaning that my query seems to be working fine but instead of making its way to the INCLUDE file (bottom navigation bar) it displays the following error msg instead of the included nav bar... *** error '80020009' Exception...
2
7918
by: Jessard | last post by:
Help! Hi, I'm having a bit (well a lot - it's getting annoying) of trouble using a C# class library within a VBScript on a computer other than the development machine. All the class is needed for at the moment is to create an ADODB.Connection object based on a passed in parameter. The passed in parameter is looked up in an XML document which then creates a connection string. It would then return the ADODB.Connection object. So for...
2
2661
by: Jim Lacenski | last post by:
I have a VB class that uses .NET and ADODB to write into an Excel spreadsheet (via Jet) on a server as part of a web application. ADODB is used instead of ADO.NET because it greatly simplifies the write process, and is supported for use on a server. (Excel is not supported (1), licensing issues with OWC). The routine works fine for a user at the server, but when a user from a system other than the server runs the page the error...
5
3009
by: mattiassich | last post by:
The following code causes unhandled exception on the line: New ManagementObjectSearcher(query) Dim mos As System.Management.ManagementObjectSearcher Dim moc As System.Management.ManagementObjectCollection Dim mo As System.Management.ManagementObject Dim query As String = "SELECT * FROM Win32_OperatingSystem" mos = New System.Management.ManagementObjectSearcher(query) moc = mos.Get() For Each mo In moc
3
5607
by: Jay A. Moritz | last post by:
I have an application that loads IE and iterates through web pages to retrieve information from the page then activates specific controls to retrieve the next page and iterate through that page for it's information, etc, etc. I have found many articles from people getting COMException errors when trying to use Interop.SHDocVw from a windows service, so it's pretty apparent to me that this is a difficult application to build, but I have...
4
5330
by: dynastar | last post by:
I'm trying to send custom COMExceptions from my C# server. My test client in C# has no problem reading the HRESULT I send (say, 0x80040002). Needless to say, the MFC client in C++ allows this HRESULT only to the .tli file, which I assume is part of the client. The next thing that happens, it is converted to an SEHException with a value of 0x80004005. This happens everytime, and does it for any derivative of SEHException. Is there some...
0
1494
by: anand1206 | last post by:
hi , i am very new to .net world. I wrote a code using c# ,which trys to access the emails from exchange server public folder i am getting the below exception: System.Runtime.InteropServices.COMException (0xC0048108) at ADODB.RecordsetClass.Open(Object Source, Object ActiveConnection, CursorTypeEnum CursorType, LockTypeEnum LockType, Int32 Options) and i tried the sample code as shown below. exception is caused at
1
2847
by: wagugwe | last post by:
Dear all, Am faced with the above problem. I am designing an application in VB.Net 2003 and using Ms Access 2000 as the database. I have the following code: Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click Try Dim response As Short response = MsgBox("Is the above information correct?", MsgBoxStyle.YesNo, "UBOS")
0
9519
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10213
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10163
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10000
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9040
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2920
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.