1个回答
展开全部
简单的数据库操作类
public class conn
{
public OleDbConnection con;
public OleDbCommand command;
public OleDbDataReader dr;
public OleDbDataAdapter ada;
public conn()
{
try
{
con = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source="+System.Web.HttpContext.Current.Server.MapPath("你的数据库地址"));
con.Open();
}
catch (InvalidOperationException one)
{
System.Web.HttpContext.Current.Response.Write(one.Message);
return;
}
catch (OleDbException two)
{
System.Web.HttpContext.Current.Response.Write(two.Message);
return;
}
}
public void close()
{
con.Close();
}
public void cmd(string str,int m)
{
command = new OleDbCommand(str,con);
try
{
if(m==1)
{
command.ExecuteNonQuery();
}
else
{
dr = command.ExecuteReader();
}
}
catch(InvalidOperationException one)
{
System.Web.HttpContext.Current.Response.Write(one.Message);
return;
}
}
public void da(string str)
{
ada = new OleDbDataAdapter(str,con);
}
}
///////////////////////////以下是操作代码/////////////
conn con = new conn();打开数据库
con.cmd("select 数据库存放图片路径的字段 from 表 where 条件");
if(con.dr.Read())
Response.Write("<img src=\""+con.dr[0].ToString()+"\">");//输出图片
else
Response.Write("信息不存在");
con.close();//关闭数据库
public class conn
{
public OleDbConnection con;
public OleDbCommand command;
public OleDbDataReader dr;
public OleDbDataAdapter ada;
public conn()
{
try
{
con = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source="+System.Web.HttpContext.Current.Server.MapPath("你的数据库地址"));
con.Open();
}
catch (InvalidOperationException one)
{
System.Web.HttpContext.Current.Response.Write(one.Message);
return;
}
catch (OleDbException two)
{
System.Web.HttpContext.Current.Response.Write(two.Message);
return;
}
}
public void close()
{
con.Close();
}
public void cmd(string str,int m)
{
command = new OleDbCommand(str,con);
try
{
if(m==1)
{
command.ExecuteNonQuery();
}
else
{
dr = command.ExecuteReader();
}
}
catch(InvalidOperationException one)
{
System.Web.HttpContext.Current.Response.Write(one.Message);
return;
}
}
public void da(string str)
{
ada = new OleDbDataAdapter(str,con);
}
}
///////////////////////////以下是操作代码/////////////
conn con = new conn();打开数据库
con.cmd("select 数据库存放图片路径的字段 from 表 where 条件");
if(con.dr.Read())
Response.Write("<img src=\""+con.dr[0].ToString()+"\">");//输出图片
else
Response.Write("信息不存在");
con.close();//关闭数据库
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询