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 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
|
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
|
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 ?
|
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
|
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?
| |
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...
|
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...
|
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.
|
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) {}...
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |