473,734 Members | 2,211 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to serialize SqlParameter ?

hi, I would like to ask how to serialize class with members like
SqlParameter. I try to use BinaryFormatter .

[Serializable]
public class Example_Class
{

public SqlParameter sqlParam;

public Example_Class()
{
sqlParam = new SqlParameter("@ Data", SqlDbType.VarCh ar);
}
}

class App
{
[STAThread]
static void Main()
{
FileStream fs = new FileStream("Dat aFile.dat", FileMode.Create );

try
{
// Construct a BinaryFormatter and use it
// to serialize the data to the stream.
BinaryFormatter formatter = new

Example_Class dod = new Example_Class() ;
// Serialize the array elements.
formatter.Seria lize(fs, dod);

// Deserialize the array elements.
fs.Position = 0;
Example_Class dod2 = (Example_Class) formatter.Deser ialize(fs);
Console.WriteLi ne("Do both class refer to the same object? "
+ (dod.sqlParam == dod2.sqlParam)) ;
Console.ReadLin e();

}
catch (SerializationE xception e)
{
Console.WriteLi ne("Failed to serialize. Reason: " + e.Message);
Console.ReadLin e();
throw;
}
finally
{
fs.Close();
}
}

and error is :

"The type System.Data.Sql Client.SqlParam eter in Assembly System.Data,
Version=1.0.500 0.0, Culture=neutral , PublicKeyToken= b77a5c561934e08 9 is
not marked as serializable."

but I know that's possible. What I do wrong ?
How do I have to implement this?

Thanks,
Marcin

Nov 16 '05 #1
1 7532
Marcin,

You would have to mark the field with the SqlParameter as
NonSerializable (with the attribute). Then, you can implement the
IDerializationC allback interface to be notified when deserialization is
complete, so that you can re-initialize it.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Marcin" <ma*********@po czta.onet.pl> wrote in message
news:cf******** **@atlantis.new s.tpi.pl...
hi, I would like to ask how to serialize class with members like
SqlParameter. I try to use BinaryFormatter .

[Serializable]
public class Example_Class
{

public SqlParameter sqlParam;

public Example_Class()
{
sqlParam = new SqlParameter("@ Data", SqlDbType.VarCh ar);
}
}

class App
{
[STAThread]
static void Main()
{
FileStream fs = new FileStream("Dat aFile.dat", FileMode.Create );

try
{
// Construct a BinaryFormatter and use it
// to serialize the data to the stream.
BinaryFormatter formatter = new

Example_Class dod = new Example_Class() ;
// Serialize the array elements.
formatter.Seria lize(fs, dod);

// Deserialize the array elements.
fs.Position = 0;
Example_Class dod2 = (Example_Class) formatter.Deser ialize(fs);

Console.WriteLi ne("Do both class refer to the same object? "
+ (dod.sqlParam == dod2.sqlParam)) ;
Console.ReadLin e();

}
catch (SerializationE xception e)
{
Console.WriteLi ne("Failed to serialize. Reason: " + e.Message); Console.ReadLin e();
throw;
}
finally
{
fs.Close();
}
}

and error is :

"The type System.Data.Sql Client.SqlParam eter in Assembly System.Data,
Version=1.0.500 0.0, Culture=neutral , PublicKeyToken= b77a5c561934e08 9 is
not marked as serializable."

but I know that's possible. What I do wrong ?
How do I have to implement this?

Thanks,
Marcin

Nov 16 '05 #2

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

Similar topics

5
3134
by: Kenneth | last post by:
Can anyone explain me why it is neccesary to include SqlDbType to the SqlParameter. In every example I see, it is done, but no one explaines why. I have for example a date I want to save into my Sql Server database through a stored procedure-call. In the database it is defined as a SmallDateTime. Every 3 methods in the client-code below gives the same (and correct) result. So why is it that important? dim param As SqlParameter
2
3856
by: confused | last post by:
Hi, I want to assign a default value of DBNull.Value to my stored procedure parameter, but also have the ability to overwrite it, so: SqlParameter param = new SqlParameter ("@EmployeeId",SqlDbType.Char,10); param.Value = DBNull.Value; //but want to overwrite maybe
5
4602
by: Daniel Groh | last post by:
What is the best way to access a procedure ? MyCommand.Parameters.Add("@param1",typeof(string)); or SqlParameter myParam = new SqlParameter(); myParam.Add("@param1",typeof(string)); What do you think ?
4
4336
by: Jason Huang | last post by:
Hi, I want to use the Sqlparameter and SqlDataAdapter to update my data, and the data will be updated based on two TextBoxes txtCustName and txtCustAddress. Thanks for help. Jason
5
8300
by: Jason Huang | last post by:
Hi, The SqlParameter myPM =new SqlParameter("@Address", txtAddress.Text) is working for update, but SqlParameter myPM =new SqlParameter ("@Address",SqlDbType.NVarChar,90,txtAddress.Text) is not working. The Address column is DataType NVarChar 90, no problem. Any idea?
0
2754
by: Elliot M. Rodriguez | last post by:
I implemented a very small, basic data access layer for my web application. It works just fine, except for this one bug. One of my methods returns an abstracted dataset. To accomodate X number of input parameters, I created a function signature that accepts a ParamArray of SqlParameters as well as the name of the stored proc. In the body of the function I loop through the param array and append each object to the Parameters collection of...
3
2763
by: Stacey Levine | last post by:
I have a webservice that has the below procedure. Basically a procedure to called a stored procedure and return the results. When I try to call the webservice from my program I get the error. Both my calling code and the webservice code are below. Thanks for your help. D:\Projects .NET\StoreBO\frmVoids.vb(182): Value of type '1-dimensional array of System.Data.SqlClient.SqlParameter' cannot be converted to '1-dimensional array of...
3
15175
by: Mirek Endys | last post by:
What is the best way to serialize object, that contains data in interfaces. Simple. I have instance of my object, that contains data in interfaces. What is the best way to XMLSerialize and deserialize this object? Thanks.
6
7841
by: Tim Zych | last post by:
' Declare a new parameter object Dim param() As SqlParameter = New SqlParameter(0) {} ' Set this to null and make it an InputOutput parameter param(0) = New SqlParameter("@Something, DBNull.Value) ' Can also be non-null, but sometimes is null param(0).Direction = ParameterDirection.InputOutput ' But, before we begin, store a copy of the existing parameters into another variable Dim param2() As SqlParameter = New SqlParameter(0) {}...
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8776
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
9310
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...
0
9182
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
8186
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...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
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.