3个回答
推荐于2017-12-15
展开全部
private string ConnStr = "数据库路径";
protected OleDbConnection conn = new OleDbConnection();
protected OleDbCommand comm = new OleDbCommand(); conn.ConnectionString = @"Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + ConnStr;//
comm.Connection = conn; conn.Open(); string sqlstr=“查询语句"; DataTable tmptable=dataTable(sqlstr);foreach(DataRow dr in tmptable.Rows){ sqlstr="修改语句";excuteSql(sqlstr);} private DataTable dataTable(string sqlstr)
{
DataTable dt = new DataTable();
OleDbDataAdapter da = new OleDbDataAdapter();
try
{
openConnection();
comm.CommandType = CommandType.Text;
comm.CommandText = sqlstr;
da.SelectCommand = comm;
da.Fill(dt);
}
catch (Exception e)
{
throw new Exception(e.Message);
}
finally
{
closeConnection();
}
return dt;
}//返回指定sql语句的datatable private string excuteSql(string sqlstr)
{
try
{
openConnection();
comm.CommandType = CommandType.Text;
comm.CommandText = sqlstr;
comm.ExecuteNonQuery();
}
catch (Exception e)
{
return e.Message.ToString();
}
finally
{ closeConnection(); }
return "";
}//执行sql语句
protected OleDbConnection conn = new OleDbConnection();
protected OleDbCommand comm = new OleDbCommand(); conn.ConnectionString = @"Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + ConnStr;//
comm.Connection = conn; conn.Open(); string sqlstr=“查询语句"; DataTable tmptable=dataTable(sqlstr);foreach(DataRow dr in tmptable.Rows){ sqlstr="修改语句";excuteSql(sqlstr);} private DataTable dataTable(string sqlstr)
{
DataTable dt = new DataTable();
OleDbDataAdapter da = new OleDbDataAdapter();
try
{
openConnection();
comm.CommandType = CommandType.Text;
comm.CommandText = sqlstr;
da.SelectCommand = comm;
da.Fill(dt);
}
catch (Exception e)
{
throw new Exception(e.Message);
}
finally
{
closeConnection();
}
return dt;
}//返回指定sql语句的datatable private string excuteSql(string sqlstr)
{
try
{
openConnection();
comm.CommandType = CommandType.Text;
comm.CommandText = sqlstr;
comm.ExecuteNonQuery();
}
catch (Exception e)
{
return e.Message.ToString();
}
finally
{ closeConnection(); }
return "";
}//执行sql语句
2013-11-09
展开全部
连接数据库读出你要进行修改的数据保存到datatable中在页面进行修改将修改的数据传入update语句执行就行了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-11-09
展开全部
用 System.Data.SqlClient.SqlCommandBuilder 可以实现你要的效果 在baidu里面 搜索 C# SqlCommandBuilder 随便点开一点 就是你想要的效果
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询