Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

How can I save VB.NET user defined type in SQL2000 DataBase???

For example:

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

 tags [/ vb][/edit][/color]
Edited by Robby
  • *Experts*
Posted

The short answer is, you can't.

 

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 you'd have to issue a "CREATE TABLE..." command? That would require dbadmin privileges to create tables in the database you're connected to.

 

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

 

-nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
  • *Gurus*
Posted
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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...