|
-
Jun 24th, 2005, 08:04 AM
#1
Thread Starter
PowerPoster
C# and SQL types
Hi there, this is a similar Q as my other thread but not the same...
What I am wondering is, in SQL we can stores binary. And in C# we have to make byte[] object and then send that value stored in the byte[] paramater to SQL and its stored.
but when RETRIEVING from SQL using dataReader, and that value to retrieve is of SQL binary.... what type should I use in order to retrieve the value?
i.e:
Code:
object theDataReadFromSQL;
while(dataReader.Read())
{
theDataReadFromSQL = dataReader.GetValue(0);
}
thats fine but the thing is, I cannot compare the bytes with the bytes of something else, as the bytes stored in theDataReadFromSQL is of type object.
its hard to explain... but i hope you understand...?
-
Jun 24th, 2005, 08:24 AM
#2
Re: C# and SQL types
I've never had to use it but the DataReader has a GetBytes method. Would that not be more appropriate method than GetValue
-
Jun 24th, 2005, 08:26 AM
#3
Thread Starter
PowerPoster
Re: C# and SQL types
I remember looking at it however I do not know what parameters to give it.... 
what should i give the parameters? I do not understand the last 3/4 of them...
-
Jun 24th, 2005, 08:58 AM
#4
Re: C# and SQL types
theres an example here of reading and writing blobs
-
Jun 24th, 2005, 09:06 AM
#5
Thread Starter
PowerPoster
Re: C# and SQL types
thanks, im just trying it but tryin to figure out how to compare the long bytes value given from SQL to the bytes calculated from the textbox on the form...
[edit]
Just tried that suggestion, its not giving me the thing i want, it gives me the length of the value retrieved. maybe you misunderstood what I said?
[/edit]
Last edited by Techno; Jun 24th, 2005 at 09:12 AM.
-
Jun 24th, 2005, 09:26 AM
#6
Thread Starter
PowerPoster
Re: C# and SQL types
currently I have a way but the thing is im using object type to get the value from SQL using dataReader.GetValue(0) then compare that with the object value of bytes of the textbox - gets me the correct bytes but the one on the textbox is less than 50 chars... anythin from sql will be of length 50 chars.
I dont want to have to do an unprofessional string concat stuff to make the value of length 50 chars
-
Jun 24th, 2005, 09:41 AM
#7
Re: C# and SQL types
 Originally Posted by Techno
[edit]
Just tried that suggestion, its not giving me the thing i want, it gives me the length of the value retrieved. maybe you misunderstood what I said?
[/edit]
byte outbyte[] = new byte[50];
retval = myReader.GetBytes(1, 0, outbyte, 0, 50);
retval stores the number of bytes read.
outbyte stores the actual data.
-
Jun 24th, 2005, 09:44 AM
#8
Thread Starter
PowerPoster
Re: C# and SQL types
excellent! thanks for this 
but now... to somehow make the bytes value contained in the textbox the same length as outbyte[]
-
Jun 24th, 2005, 10:11 AM
#9
Re: C# and SQL types
you could try an Array.Copy
byte[] dest = new byte[50]
Array.Copy(source,0,dest,0,source.Length);
-
Jun 24th, 2005, 10:19 AM
#10
Thread Starter
PowerPoster
Re: C# and SQL types
thanks 
looks good but when i do an if statement like this, its always returned as false!
Code:
if(dest == source)
{
}
else
{
//always goes here!
}
but I have looked at both of the values and both are the same! Same result occurs if I do a .Equals()
-
Jun 24th, 2005, 10:31 AM
#11
Re: C# and SQL types
AFAIK == and Equals compare references unless the class overides them so that they explicitly perform a comparsion on the contents.
I guess a loop is needed to check each item.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|