Dzwebs.Net

撰写电脑技术杂文十余年

Sql远程数据库与本地数据库的导入导出源代码—与虚拟主机黑店之斗智斗勇下篇

Admin | 2008-7-15 13:26:02 | 被阅次数 | 6629

温馨提示!

如果未能解决您的问题,请点击搜索;登陆可复制文章,点击登陆

        接上篇……

   //通过参数传递数据,将数据插入到本地数据库!
    private void DataInOut(string Title, string ColumnsID, string Detail, string DateTime, string Audit, string UserName,string ReadNum)
    {
        SqlConnection mycon = new SqlConnection("server=localhost;uid=sa;pwd='密码';database=数据库名");
        mycon.Open();
        SqlTransaction mytrans = mycon.BeginTransaction();
        // 为事务创建一个命令
        SqlCommand mycmd = new SqlCommand("insert into 数据表名(Title,ColumnsID,Detail,DateTime,Audit,UserName,ReadNum) values(@Title, @ColumnsID, @Detail, @DateTime, @Audit, @UserName,@ReadNum)", mycon);

        mycmd.Parameters.Add(new SqlParameter("@Title", SqlDbType.VarChar, 8000));
        mycmd.Parameters["@Title"].Value = Title;

        mycmd.Parameters.Add(new SqlParameter("@ColumnsID", SqlDbType.Int, 4));
        mycmd.Parameters["@ColumnsID"].Value = ColumnsID;

        mycmd.Parameters.Add(new SqlParameter("@Detail", SqlDbType.VarChar, 8000));
        mycmd.Parameters["@Detail"].Value = Detail;
        mycmd.Parameters.Add(new SqlParameter("@DateTime", SqlDbType.VarChar, 8000));
        mycmd.Parameters["@DateTime"].Value = DateTime;
        mycmd.Parameters.Add(new SqlParameter("@Audit", SqlDbType.VarChar, 8000));
        mycmd.Parameters["@Audit"].Value = Audit;
        mycmd.Parameters.Add(new SqlParameter("@UserName", SqlDbType.VarChar, 8000));
        mycmd.Parameters["@UserName"].Value = UserName;
        mycmd.Parameters.Add(new SqlParameter("@ReadNum", SqlDbType.Int, 4));
        mycmd.Parameters["@ReadNum"].Value = ReadNum;

        mycmd.Connection = mycon;
        mycmd.Transaction = mytrans;
        try
        {
            mycmd.ExecuteNonQuery();
            mytrans.Commit();
        }
        catch (Exception ex)
        {
            mytrans.Rollback();
            Response.Write(ex.ToString().Trim());
        }
        finally
        {
            mycon.Close();
        }
    }
}


该杂文来自: 网站开发杂文

上一篇:Sql远程数据库与本地数据库的导入导出源代码—与

下一篇:新购买的域名如何绑定到指定的主机IP

网站备案号:

网站备案号:滇ICP备11001339号-7

版权属性:

Copyright 2007-2021-forever Inc. all Rights Reserved.

联系方式:

Email:dzwebs@126.com QQ:83539231 访问统计