alexk Posted April 2, 2003 Posted April 2, 2003 (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 April 2, 2003 by Robby Quote
*Experts* Nerseus Posted April 2, 2003 *Experts* Posted April 2, 2003 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 Quote "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* Derek Stone Posted April 3, 2003 *Gurus* Posted April 3, 2003 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. Quote Posting Guidelines
alexk Posted April 3, 2003 Author Posted April 3, 2003 To: Derek Stone Thank You!!! Yor post was short but very helpfull and to the point. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.