
展开全部
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语句
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询