先重载方法,前一个是Sql,后一个是Sql参数集合
插入方法:
public static int ExecuteSql(string SQLString,OleDbParameterCollection parms)
{
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
connection.Open();
using (OleDbCommand cmd = new OleDbCommand(SQLString, connection))
{
cmd.Parameters.AddRange(parms);
cmd.ExecuteNonQuery();
}
connection.Close();
}
}
读取方法:
public object SqlRead(string sqlstring)
{
using (OleDbConnection cn = new OleDbConnection(connectionString))
{
cn.Open();
using (OleDbCommand cmd = new OleDbCommand(sqlstring, cn))
{
object obj=cmd.ExecuteScalar();
if (obj == null)
{
MessageBox.Show("数据库中目前没有数据,请先存入!");
}
else
{
return obj;
}
}
cn.Close();
}
}
上面两个方法呢,写到你的那个啥类里面的
调用的时候呢,就
插入:
System.IO.MemoryStream ms = new System.IO.MemoryStream();
this.richTextBox1.SaveFile(ms, RichTextBoxStreamType.RichText);
OleDbParameterCollection param= new OleDbParameterCollection();
param.Add(new OleDbParameter("@rtf",ms));
XX类的.ExecuteSql("insert into [demo] (rtf) values (@rtf)",param);
读取
byte[] buff=(byte[])XX类的.SqlRead("select top 1 rtf from [demo] order by [id] desc");
System.IO.MemoryStream ms = new System.IO.MemoryStream(btRTF);
rtbDemo.LoadFile(ms, RichTextBoxStreamType.RichText);
其中XX类是你那个啥类
数据是用什么方式写进去的呢?
已经发到你的邮箱,请查收。