返回列表 发帖

09版易控与sql链接

麻烦问下一如果把ACCESS数据库改为和SQL 2008连接,下面的脚本应该怎么改,谢谢


public static void 数据库连接(string sql)
{
string filename= Path.Combine(SystemGroup.ProjectPath,"配料报表数据.mdb");
string zcon=string.Format(@"Provider=microsoft.jet.oledb.4.0;data source='{0}';",filename);
using (OleDbConnection ole = new OleDbConnection(zcon))//创建数据库连接
      {
                try
                {
                    ole.Open();//打开数据库连接

                    OleDbCommand cmd = new OleDbCommand(sql,ole);//执行SQL查询语句
                    cmd.ExecuteNonQuery();//执行语句
                }

                catch (Exception ee)
                {
                    Trace.WriteLine(ee.Message);
                }
                finally
                {
                    ole.Close();
                }
            }
            
}

返回列表