oracle建表语句
Create table blogtest(id number primary key,name varchar2(20),picture blob);
C#写入数据库中
/// <summary>
/// 增加一条数据
/// </summary>
public int Add(BlogTestInfo model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into BlogTest(");
strSql.Append("ID,Name,Picture)");
strSql.Append(" values (");
strSql.Append("SEQ_BlogTestID.Nextval,:Name,:Picture)");//SEQ_BlogTestID 是数据库中的序列
Database db = DatabaseFactory.CreateDatabase();
DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
//db.AddInParameter(dbCommand, ":ID", DbType.String, model.ID);
db.AddInParameter(dbCommand, ":Name", DbType.String, model.Name);
//字符窜转成byte[] 加入数据库中
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(model.Picture.ToString());
db.AddInParameter(dbCommand, ":Picture", DbType.Binary, bytes);
int rows= db.ExecuteNonQuery(dbCommand);
return rows;
#region OraAcess
//StringBuilder strSql = new StringB:REMARK2", Oracluilder();
//strSql.Append("insert into MONRE:REMARK3", OraclPORTCOMMENTS(");
//strSql.Append("ID,CLIENTID,PRODUCTTYPEID,COMPANYID,SALESDATE,REMARK1,REMARK2,REMARK3)");
//strSql.Append(" values (");
//strSql.Append(":ID,:CLIENTID,:PRODUCTTYPEID,:COMPANYID,:SALESDATE,:REMARK1,:REMARK2,:REMARK3)");
//Oracle.DataAccess.Client.OracleParameter[] parameters = {
// new Oracle.DataAccess.Client.OracleParameter(":ID", Oracle.DataAccess.Client.OracleDbType.NVarchar2),
// new Oracle.DataAccess.Client.OracleParameter(":CLIENTID", Oracle.DataAccess.Client.OracleDbType.Int32,4),
// new Oracle.DataAccess.Client.OracleParameter(":PRODUCTTYPEID", Oracle.DataAccess.Client.OracleDbType.Int32,4),
// new Oracle.DataAccess.Client.OracleParameter(":COMPANYID", Oracle.DataAccess.Client.OracleDbType.Int32,4),
// new Oracle.DataAccess.Client.OracleParameter(":SALESDATE", Oracle.DataAccess.Client.OracleDbType.Date),
// new Oracle.DataAccess.Client.OracleParameter(":REMARK1", Oracle.DataAccess.Client.OracleDbType.NVarchar2),
// new Oracle.DataAccess.Client.OracleParameter(":REMARK2", Oracle.DataAccess.Client.OracleDbType.NVarchar2),
// new Oracle.DataAccess.Client.OracleParameter(":REMARK3", Oracle.DataAccess.Client.OracleDbType.NVarchar2)};
//parameters[0].Value = model.ID;
//parameters[1].Value = model.ClientID;
//parameters[2].Value = model.ProductTypeID;
//parameters[3].Value = model.CompanyID;
//parameters[4].Value = model.SalesDate;
//parameters[5].Value = model.Remark1;
//parameters[6].Value = model.Remark2;
//parameters[7].Value = model.Remark3;
//OracleDataAccessHelper helper = new OracleDataAccessHelper();
//int rows = helper.ExecuteNonQuery(strSql.ToString(), parameters);
//return rows;
#endregion OraAcess
}
读取方法
protected DataTable GetDataTable()
{
DataTable dt = new DataTable();
//获取数据
//BLL.SalesBLL bll = new SalesBLL();
string saleDate = this.txtDate.Text.Trim().Replace("-", "");
dt = bll.GetDataTable();
if (dt.Rows.Count > 0)
{
DataRow dr = dt.Rows[0];
BlogTestInfo model=new BlogTestInfo();
model.id=int.Parse(dr["ID"].ToString());
//this.tbRemark1.Text = dr["Remark1"].ToString();
if (dr["Picture"] != null && dr["Picture"] != DBNull.Value)
{
//byte[] b = System.Text.Encoding.ASCII.GetBytes(dr["Remark1"]);
byte[] b = (byte[])dr["Picture"];
//byte[] 转成 字符窜
model.Text = System.Text.Encoding.UTF8.GetString(b);//dr["Remark1"].ToString();
}
}
}
return dt;
}