有一数据库data,其内容如下:
id title content date
1 223 12412 54
2 542 87545 65
3 778 98565 74
4 514 54874 32
现在我想将id为3的那条记录的content字段的值,并且将它负值给sum,这个代码该怎么写?
id title content date
1 223 12412 54
2 542 87545 65
3 778 98565 74
4 514 54874 32
现在我想将id为3的那条记录的content字段的值,并且将它负值给sum,这个代码该怎么写?
解决方案 »
- 关于从数据库查询信息和对比的问题,求高人指教谢谢。
- 一直对对象的方法的实现很模糊,大虾们指点下。。
- 急!!!!using System.Web.UI.WebControls.Image.Imageurl中图片显示问题
- C#如果取得字符的点阵信息?
- 关于remoting问题
- 关于字符串的问题
- 懂得把remoting写在windows服务中的进来帮我看一下
- 控件无法重命名
- 请教一个类中方法实现的问题
- 公司要测试一下.net开发,请问有无测试版的vs.net2003下载
- 如何设置winform中label的Text的行间距和字符间距
- 怎么把C#的datetime格式转换为DWord的time_t?请帮忙,谢谢.
string sqlstring ,field;
sqlstring="select * from data where id=3";
field=" content ";sum=Mydbfunc.ReturnSqlValue(sqlstring,field)
//名称 : string ReturnSqlValue(string sqlstring ,string filed)
//功能 : 连接数据库并执行传递过来的sql语句,返回指定字段的数据值(以字符串传回)//传入类型: string string
//传入参数: sql查询语句,指定的返回字段//返回类型; string
//返回值 : 返回查询出来的对应filed的值
////////////////////////////////////////////////////////////////////////
public string ReturnSqlValue(string sqlstring ,string filed)
{
OleDbConnection MyConnection= null;
OleDbCommand MyCommand=null;
OleDbDataReader MyDatareader=null;
try
{
MyConnection=new OleDbConnection(GetConnectionString());
MyCommand=new OleDbCommand(sqlstring,MyConnection);
MyConnection.Open();
MyDatareader=MyCommand.ExecuteReader();
if (MyDatareader.Read())
{
return Convert.ToString(MyDatareader[filed]);
}
else
{
return null;
}
}
catch
{
return null;
}
finally
{
if (MyConnection!=null)
{
MyConnection.Close();
MyConnection.Dispose();
}
if(MyCommand!=null)
{
MyCommand.Dispose();
}
if(MyDatareader!=null)
{
MyDatareader.Close() ;
}
}}