VB.NET User Defined type In SQL2000 ?

alexk

Active member
Joined
Jul 23, 2002
Messages
34
Location
Israel
How can I save VB.NET user defined type in SQL2000 DataBase???
For example:
Code:
Public Structure MyType
      Public MyVar_1 As Integer
      Public MyVar_2 As Boolean
End Structure

Dim MyObj as MyType

MyObj.MyVar_1 = 1000
MyObj.MyVar_2 = True

Dim MySQLCommand as New SqlCommand

MySQLCommand.Connection = *****
MySQLCommand.CommandText = "INSERT INTO cl_win_Sequr (TestColumn) VALUES (MyObj)"
When I try execute this command the following error message is appear: "The name MyObj is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted."

What make I wrong???
Please Help.

[edit]Please use
Code:
 tags [/ vb][/edit][/COLOR]
 
Last edited by a moderator:
The short answer is, you cant.

If you just want to save the two values, then why not create a table with an "int" column and a "bit" column? Usually, you have your tables defined first, then create your code structures to match, not the other way around - though your case may be special.

If you want to create a new structure on the fly youd have to issue a "CREATE TABLE..." command? That would require dbadmin privileges to create tables in the database youre connected to.

The user-defined-datatypes in SQL Server are nothing more than aliass for built-in types. You cant really have a user-defined-type made up of two types of values (such as int and bit).

-nerseus
 
Serialize the class and save it to a string (nvarchar) field if you must save the object as is. Otherwise do as was suggested above and use database normalization techniques to link a table that conforms to your type properties and fields to each record in your cl_win_Sequr table.
 
Back
Top