Click here to Skip to main content
15,890,186 members
Home / Discussions / Database
   

Database

 
GeneralRe: How to find number of student Pin
partyganger22-Jul-04 18:18
partyganger22-Jul-04 18:18 
AnswerRe: How to find number of student Pin
Bill Dean23-Jul-04 8:57
Bill Dean23-Jul-04 8:57 
GeneralRe: How to find number of student Pin
DotNet24-Jul-04 0:07
DotNet24-Jul-04 0:07 
Generalmutiple ODBC help!!! Pin
Member 123981322-Jul-04 16:34
Member 123981322-Jul-04 16:34 
GeneralRe: mutiple ODBC help!!! Pin
Small Rat23-Jul-04 18:52
Small Rat23-Jul-04 18:52 
QuestionCan't get value from DataSet into variable without explicit casting? Pin
ThomasH122-Jul-04 13:17
ThomasH122-Jul-04 13:17 
GeneralParsing, Processing, And Inserting Multiple Records Into a Database Design Question Pin
Member 66660722-Jul-04 10:47
Member 66660722-Jul-04 10:47 
Generalstore a c# byte array Pin
pelos22-Jul-04 6:38
pelos22-Jul-04 6:38 
hello forum,

i want to store c# objects in a MS SQL database. I think the best way is to serialize the object to a byte array but i have problems to insert a c# byte array into the database...

First, the equivalent type of datum in MS SQL is the binary or varbinary type, isn´t it?

well, my code:

<br />
<br />
MyObject mo = new MyObject();<br />
MemoryStream ms=  new MemoryStream();<br />
BinaryFormatter bf = new BinaryFormatter();<br />
b.Serialize(ms,mo);<br />
<br />
SqlConnection sc = new SqlConnection("server=localhost;uid=sa;pwd=;database=myDB");<br />
sc.Open();<br />
<br />
SqlDataAdapter sda = new SqlDataAdapter("select * from myTable",sc);<br />
DataSet ds = new DataSet();<br />
ad.Fill(ds,"tableFile");<br />
DataTable dt = ds.Tables["tableFile"];<br />
DataRow dr = dt.NewRow();<br />
<br />
dr["object"] = ms.GetBuffer(); //object is binary or varbinary<br />
                               // and GetBuffer() returns a byte[]<br />
dt.Rows.Add(dbRow);<br />
<br />
SqlCommandBuilder scb = new SqlCommandBuilder(sda);<br />
sda.Update(ds, "tableFile");<br />
<br />


The instruction:
dr["object"] = ms.GetBuffer();
throws the message exception "String or binary data would be truncated"

could you help me, please?
thanks in advance.
GeneralRe: store a c# byte array Pin
partyganger22-Jul-04 17:30
partyganger22-Jul-04 17:30 
GeneralRe: store a c# byte array Pin
pelos22-Jul-04 23:41
pelos22-Jul-04 23:41 
GeneralRe: store a c# byte array Pin
Anonymous23-Jul-04 9:29
Anonymous23-Jul-04 9:29 
GeneralRe: store a c# byte array Pin
partyganger23-Jul-04 9:30
partyganger23-Jul-04 9:30 
Generaldatagrid Pin
viviansm21-Jul-04 21:26
viviansm21-Jul-04 21:26 
GeneralRe: Very Urgent SQL query Pin
ThomasH122-Jul-04 13:20
ThomasH122-Jul-04 13:20 
GeneralRe: Very Urgent SQL query Pin
partyganger22-Jul-04 18:23
partyganger22-Jul-04 18:23 
General&quot;how to install multi database on the same machine using different names from DTS package&quot; Pin
Harmeet Singh21-Jul-04 17:28
Harmeet Singh21-Jul-04 17:28 
GeneralSQL Table Names in the Header Pin
Cedar Sith21-Jul-04 11:55
Cedar Sith21-Jul-04 11:55 
GeneralRe: SQL Table Names in the Header Pin
Bill Dean23-Jul-04 9:14
Bill Dean23-Jul-04 9:14 
GeneralLooking for some code that imports a CSV file using ADO.NET Pin
David Flores21-Jul-04 11:09
David Flores21-Jul-04 11:09 
GeneralSQL Server engine? (packaging) Pin
xstoneheartx21-Jul-04 10:50
xstoneheartx21-Jul-04 10:50 
GeneralRe: SQL Server engine? (packaging) Pin
Anders Molin22-Jul-04 16:09
professionalAnders Molin22-Jul-04 16:09 
GeneralA Challenging SQL Server Puzzle Pin
partt21-Jul-04 6:31
partt21-Jul-04 6:31 
GeneralRe: A Challenging SQL Server Puzzle Pin
Steven Campbell21-Jul-04 7:09
Steven Campbell21-Jul-04 7:09 
GeneralRe: A Challenging SQL Server Puzzle Pin
michanne121-Jul-04 18:22
michanne121-Jul-04 18:22 
GeneralChoosing a new db technology Pin
KMerker21-Jul-04 1:50
KMerker21-Jul-04 1:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.