hi all,
I want to save content of RichTextBox (image, text etc.) to in binary or image field in SQL Server, but I couldn't...
Please help me, thank you
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Wim DevosPosted Jun 16, 2007, 10:19 AM
Ersin MimanPosted Jun 16, 2007, 9:55 AM
Can I use these method to save and read to/from binary field to SQL Server?
MemoryStream ms_memStream = new MemoryStream();
BinaryWriter br_binaryWriter = new BinaryWriter(ms_memStream);
br_binaryWriter.Write("sample text");
But, I don't know how will to use it?
sqlCommand1.CommandText = "INSERT INTO tbT_Soru(SoruBinary) VALUES(" + ms_memStream.ToString() + ")"; ????????
nguyen huu thoPosted Jun 16, 2007, 9:46 AM
Ersin MimanPosted Jun 16, 2007, 8:34 AM
FileStream inFile;
Byte[] binaryData;
try
{
inFile =
new FileStream("ersin miman", FileMode.Open, FileAccess.Read);binaryData =
new Byte[inFile.Length];}
catch (Exception exp){
// Error creating stream or reading from it.System.
Console.WriteLine("{0}", exp.Message); return;}
sqlConnection1.ConnectionString =
"Data Source=localhost;Initial Catalog=dbSoru;User ID=sa;Password=xxxxxx";sqlConnection1.Open();
SqlTransaction trs = null; try{
trs = sqlConnection1.BeginTransaction();
sqlCommand1.Connection = sqlConnection1;
sqlCommand1.CommandText =
"INSERT INTO tbT_Soru(SoruBinary) VALUES('" + binaryData + "')";sqlCommand1.Transaction = trs;
sqlCommand1.ExecuteNonQuery();
trs.Commit();
}
catch (Exception e1){
if (trs != null){
trs.Rollback();
}
}
sqlConnection1.Close();
Wim DevosPosted Jun 16, 2007, 7:37 AM