• .net Access 新增记录后获取自动编号的值


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.OleDb;

    namespace WindowsApplication2
    {
        public partial class Form1 : Form
        {
            OleDbConnection myConnection;
            public Form1()
            {
                InitializeComponent();
            }

            private void Form1_Load(object sender, EventArgs e)
            {
              myConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Logs.mdb;Persist Security Info=False");
              string cmdText="insert   into   LogInfo   (LeiBie)   values('bbb')";

              int sss=returnID(cmdText);
         
            }
            /// <summary>
            ///
            /// </summary>
            /// <param name="sql"></param>
            /// <returns></returns>
            public  int returnID(string sql)
            {
                int nID = 0;
                try
                {
                    myConnection.Open();
                    OleDbTransaction myTransaction = myConnection.BeginTransaction(IsolationLevel.ReadCommitted);
                    OleDbCommand myCommand = new OleDbCommand(sql, myConnection);
                    myTransaction.Commit();
                    myCommand.ExecuteNonQuery();
                    myCommand.CommandText = "select @@identity as id";
                    nID = Convert.ToInt32(myCommand.ExecuteScalar());
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message);
                }
                finally
                {
                    myConnection.Close();
                }
                return nID;
            }

        }
    }

  • 相关阅读:
    记一次HTTP劫持故障排查
    前面任意字符+固定字符+任意字符+固定字符匹配
    php-fpm启动,重启,终止操作
    crontab防止脚本周期内未执行完重复执行
    js深拷贝和浅拷贝
    vue 异步刷新页面,
    vue强制刷新组件
    js判断终端以及APP应用判断
    微信返回上一页的按钮会强制性使用页面缓存,不刷新页面
    json键和值转数组
  • 原文地址:https://www.cnblogs.com/chenghm2003/p/1271790.html
Copyright © 2020-2023  润新知