惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Cisco Talos Blog
Cisco Talos Blog
T
Threat Research - Cisco Blogs
P
Privacy International News Feed
S
Schneier on Security
P
Privacy & Cybersecurity Law Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
Scott Helme
Scott Helme
人人都是产品经理
人人都是产品经理
G
GRAHAM CLULEY
O
OpenAI News
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
PCI Perspectives
PCI Perspectives
GbyAI
GbyAI
宝玉的分享
宝玉的分享
Y
Y Combinator Blog
T
Troy Hunt's Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
腾讯CDC
C
Check Point Blog
Spread Privacy
Spread Privacy
L
LINUX DO - 最新话题
Recent Announcements
Recent Announcements
大猫的无限游戏
大猫的无限游戏
P
Palo Alto Networks Blog
Hacker News: Ask HN
Hacker News: Ask HN
M
MIT News - Artificial intelligence
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Hacker News
The Hacker News
H
Hacker News: Front Page
Microsoft Azure Blog
Microsoft Azure Blog
I
InfoQ
T
Tor Project blog
Martin Fowler
Martin Fowler
博客园 - 叶小钗
罗磊的独立博客
C
Cyber Attacks, Cyber Crime and Cyber Security
H
Heimdal Security Blog
V
Vulnerabilities – Threatpost
Simon Willison's Weblog
Simon Willison's Weblog
Latest news
Latest news
WordPress大学
WordPress大学
G
Google Developers Blog
N
Netflix TechBlog - Medium
S
Security Affairs
S
Secure Thoughts
Know Your Adversary
Know Your Adversary

博客园 - hemingchen

MiniProfiler asp.net MVC控制器中返回JSON格式的数据时提示下载 Delphi XE2 新技术说明 (What's new in Delphi XE2)(转载) Microsoft.VisualStudio.Xaml 加载错误 解决 网页如何有效调用exe js parentElement - hemingchen - 博客园 Response.ContentType 详细列表 - hemingchen - 博客园 SQL 2005 开启OpenRowset/OpenDatasource的办法 常用正则表达式 - hemingchen - 博客园 XMLHTTP 保护自己的眼睛 转载 37个Ajax和CSS实现的Tab选项卡切换效果界面 SQL2005附加数据库"失败........无法更新数据库"xxx",因为数据库是只读 - hemingchen - 博客园 asp.net C# 下母版页使用 JavaScript 脚本文件编码导致的问题 jquery json简单例子 jquery ajax xml jquery学习 使用面向对象的技术创建高级 Web 应用程序 文章来源:http://msdn.microsoft.com/zh-cn/magazine/cc163419.aspx本文讨论:
.net Access 新增记录后获取自动编号的值
hemingchen · 2008-08-19 · via 博客园 - hemingchen

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;
        }

    }
}