473,395 Members | 2,151 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,395 software developers and data experts.

What's a System.__ComObject? Where's my SQL Server value?

I can't assign a MS SQL Server table record value to a simple VB variable, should be a really easy thing. Sample SQL Server table has the data in the record as a char(30) string, the column for that record is named "Try". The VB script function accessing the record value is running on a web hosting server with ASP.Net 2.0 on a web page. Result always is it "can't convert from a Field to type 'String'". Printing out the SQL variable results "System.__ComObject". I know this is a wrapper, but how do I get in and access my value?

I have tried CAST and CONVERT SQL commands. Also, if I create a Gridview and tie the data source to the SQL database, it displays the table values just fine, but I need to apply the values to a formula and can't use the raw values from the SQL table so this won't work for me. Going the opposite way, setting the SQL table value to any VB value always works good. Is ASP.Net 2.0 overtaking the Com wrapper?

Anyone have ideas on how to make this go away?


Expand|Select|Wrap|Line Numbers
  1. <script runat="server">
  2.   Dim SampleString as String 'here's where we want the string data from the SQL table
  3.  
  4.   Public Sub SaveSignals()
  5.     Dim Connection1 As Object
  6.     Dim MyTable As Object
  7.     Dim Query As String
  8.     Dim ConnectionString As String
  9.  
  10.     ConnectionString = "Provider=SQLOLEDB;" & _
  11.           "Data Source=server;" & _
  12.           "Initial Catalog=tablename;" & _
  13.           "User ID=userid;" & _
  14.           "Password=pw1234"
  15.     Connection1 = CreateObject("ADODB.Connection") 'make a connection
  16.     Connection1.open(ConnectionString)
  17.  
  18.     MyTable = CreateObject("ADODB.Recordset") 'make a table object
  19.     Query = "SELECT * FROM tablename" 'SQL command to open up the named table, get 1st record
  20.     MyTable.CursorType = 2 'adOpenDynamic
  21.     MyTable.LockType = 2 'adLockOptimistic
  22.     MyTable.open(Query, Connection1) 'opens up the table using the SQL connection
  23.     MyTable.MoveFirst() 'goes to the first record, everything works great up to here
  24.  
  25.  
  26. 'problem here
  27.  
  28.     'assign a SQL table value to my VB string variable    
  29.     SampleString=MyTable("Try") '<------ Results in error at web server:
  30.       'Exception Details: System.InvalidCastException: 
  31.       'Conversion from type 'Field' to type 'String' is not valid.
  32.  
  33.     'just for kicks, print out the value to the web page.    
  34.     Response.Write(MyTable("Try")) '<------ so if we comment out the above line so the server is ok,
  35.       'the server prints out: "System.__ComObject" on the web page, instead of my string value
  36.  
  37.  
  38.  
  39.     'when we get here, attempt to put any string value back into the SQL table    
  40.     MyTable("Try") = "TestMe" 'any data, from any string source,
  41.       ' going back to the database works great, no problems at all.
  42.  
  43.     MyTable.update()  ' Save changes, always successful
  44.  
  45.     MyTable.Close()   ' Close table.
  46.     Connection1.Close()   ' Close table. Success always.
  47.   End Sub
  48. </script>
  49.  
Dec 4 '06 #1
1 5790
Hi, I ran into the same problem and was able to fix it by changing this:

SampleString=MyTable("Try")

to this:

SampleString=MyTable.Fields.Item("Try") .Value

I can't figure out why the syntax needs to be different, but whatever the reasons this seems to work just fine.
May 22 '08 #2

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

Similar topics

0
by: Angelos Karantzalis | last post by:
Hi y'all, here's a tricky one: I've written a wrapper around a Com Interop-generated assembly in C#. It's called SDEHandler & implements a previously defined interface, so that I can use it as a...
0
by: Fidias Gil de Montes | last post by:
In a Distributed Windows application, I receive the following message when the client calls the server: ************** Exception Text ************** System.InvalidCastException: Unable to cast...
3
by: Axel Strube-Zettler | last post by:
I'm stuck now for a whole afternoon with a little Interop problem: static object m_ovl = m_app.GetInterfaceObject("VL.Application.nn"); (m_app.GetInterfaceObject() returns the in-process VL...
1
by: mminto | last post by:
Unable to cast COM object of type 'System.__ComObject' to interface type 'Manage.Statistics.IManageStats'. This operation failed because the QueryInterface call on the COM component for the...
2
by: Ron Dahl | last post by:
In Word VBA the expression "ActiveDocument.Paragraphs(1).Style returns "Heading 3" In VB.Net the expression "appWord.ActiveDocument.Paragraphs(1).Style" returns "{System.__ComObject} :...
2
by: stunt016 | last post by:
I have a program written in C# that handles communication between two pieces of software. My problem only deals with getting a text array from one program to this C# "Bridge". I can get the text...
0
by: woollymammoth | last post by:
I can't assign a MS SQL Server table record value to a simple VB variable, should be an easy thing. Sample SQL Server table has the data in the record as a char(30) string, the column for that record...
2
by: les | last post by:
I have a c# class that I want to work, when compiled into a dll, either in asp.net or classic asp 3.0. It references System.EnterpriseServices and ASPTypeLibrary and as far as the dll used either...
0
by: dhaval321 | last post by:
Hello, Actually i am making plugin in spinfire software..And when i m using threading then the error of "Unable to cast COM object of type 'System.__ComObject' to interface type...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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,...

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.