|
No need to apologize, Vikram; thanks for answering.
Software Zen: delete this;
|
|
|
|
|
Can anyone tell me what would be the appropriate data type to use in C# when reading and writing to binary fields in a Sybase database? Thank you in advance.
Modified:
I have a byte[] populated with 33 values. I'm using a stored proc that has a binary parameter. I'm assigning the parameter the byte[], but I'm only getting 1-byte to write and I'm not even sure it has anything to do with the value that should be written.
modified on Thursday, January 15, 2009 4:08 PM
|
|
|
|
|
You haven't given much information to go on, so the generic answer would be byte[] .
modified on Thursday, January 15, 2009 1:09 PM
|
|
|
|
|
Please see original post. I modified it. Thanks again.
|
|
|
|
|
Without seeing the code you're using to pass the byte array to the database, it's difficult to say what's going wrong.
|
|
|
|
|
////////////////////////////////////////
// SQL
////////////////////////////////////////
CREATE PROCEDURE InsertBinData(
@binData BINARY
)
BEGIN
INSERT INTO Table1 ( BinData ) VALUES @binData
END
////////////////////////////////////////
// C#
////////////////////////////////////////
byte[] data = new byte[33];
// function call to fill byte array here
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Clear();
command.Parameters.AddWithValue( "@binData", data );
command.CommandText = "InsertBinData";
Command.ExecuteNonQuery();
|
|
|
|
|
mobius111001 wrote: byte[] data = new byte[33];
// function call to fill byte array here
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Clear();
command.Parameters.AddWithValue( "@binData", data );
command.CommandText = "InsertBinData";
Command.ExecuteNonQuery();
Don't use AddWithValue . Use the full technique of creating a Parameter object, setting it's database type and direction properly and then assign the value to it and add it to the collection. Here, you're assuming that the object will correctly guess the correct database type to use, when, in fact, it can get it wrong.
|
|
|
|
|
i still only get the byte[0] to write out.
OdbcConnection cn = new OdbcConnection(); // assuming db connection made correction
OdbcCommand cm = new OdbcCommand();
Random r = new Random( ( int )DateTime.Now.Ticks );
OdbcParameter op;
cm.Connection = cn;
byte[] b = new byte[32];
for ( int i = 0; i < b.Length; i++ )
{
b[i] = ( byte )( r.Next() % 256 );
}
cm.CommandType = CommandType.StoredProcedure;
cm.Parameters.Clear();
op = cm.Parameters.Add( "@binVal", OdbcType.Binary );
op.Direction = ParameterDirection.Input;
op.Size = b.Length;
op.Value = b;
cm.CommandText = "sp_SaveBinaryVal";
cn.Open();
try
{
cm.ExecuteNonQuery();
}
finally
{
if ( cn.State == ConnectionState.Open )
{
cn.Close();
}
}
|
|
|
|
|
Hi Everyone
I have a rtf file which is simillar to a csv file but here the delimitting character is "|".I want to read the data in rtf file to a datatable. Please some body help me
Thanks in advance
|
|
|
|
|
Hi srinivasadithya,
You can build your own RTF Converter[^] by using the TextConverter class, split any line using String.Split( '|' ) and write the tokens to a System.Data.DataTable .
Cheers,
Jani
|
|
|
|
|
Dear jani
What is the Assembly referance for rtfConverter
could you please elaborate that
Regards
|
|
|
|
|
Hi srinivasadithya,
You have to reference the Assemblies Itenso.Sys.dll , Itenso.Rtf.Parser.dll and Itenso.Rtf.Interpreter.dll . These assemblies are located in the \bin\Debug\ folder.
The sample project Rtf2Raw200x.sln demonstrates how you can extract the text from a RTF file.
Cheers,
Jani
|
|
|
|
|
can somebody explain me Asynchoronous multithreading.
Thanks in Advance...
vikas da
|
|
|
|
|
|
Thank you very much i think i got, what i was looking for ..
vikas da
|
|
|
|
|
I'm calling a method in class Bar from an instance of class Foo.
Bar needs to be able to broadcast to other objects the Foo instance. I can get the Type easily by using the System.Diagnostics.StackTrace class (I know about the low performance!) but the only way I can get the instance is to pass it as a parameter to Bar which I'd like to avoid.
Is this possible?
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
can't you just use "this"?
|
|
|
|
|
this would give the Bar instance not the Foo instance
|
|
|
|
|
Couldn't the bar class just raise an event that Foo would handle?
|
|
|
|
|
The Bar class is raising an event basically on behalf of the Foo instance. Other objects will be subscribed to Bar's events, but not to the Foo instance, so I'm trying to pass the Foo instance as if it was passing itself as sender if it was raising the event itsef.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
|
Unfortunately Foo isn't the parent of Bar and if it were, Bar could have many differnet parents. Thanks anyway!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Sorry Dave - it's not possible (well not with .NET currently). As Bar could be called from any number of different types of classes, this just isn't possible. However, this does sound vaguely like you're trying to do something similar to the http://www.dofactory.com/Patterns/PatternMediator.aspx[^] pattern. Might that be an option instead?
|
|
|
|
|
Thanks Pete, will read that right now!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Thanks for the link - I'd never looked at that pattern - I definately need to do some re-reading to 'freshen' up.
What I'm trying to do is more of a generic Observer type pattern, but using a Singleton for the subject so it's accessible by any instance of any type. Mika and I have got quite a way into this and it's pretty much working apart from this, which is a bit ugly at the moment. I've overloaded the Notify methods so that the instance can be sent as a parameter, but I'd rather make that part automated. The reference to the original instance must surely be somewhere(stack?) for the method to be able to return?
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|