开发者

Updating an MS Access table in C#

开发者 https://www.devze.com 2023-02-10 01:41 出处:网络
I\'m working with a Microsoft Access Database in my Winforms project. I\'m using OLEDB to connect. I have the following table I\'m trying to update:

I'm working with a Microsoft Access Database in my Winforms project. I'm using OLEDB to connect. I have the following table I'm trying to update:

    TotalLogins
--------------------
ID        AutoNumber
TokenNo   Text
UserID    Number
FromDate  DateTime //Contains datetime of login
ToDate    DateTime //Contains datetime of logout

How do I write C# code that updates this table开发者_如何转开发 with all the required information?


Try this code as example

OleDbConnection cn = new OleDbConnection(conString);
            OleDbCommand cmd = new OleDbCommand();
            cmd.CommandText = "UPDATE TotalLogins SET TokenNo=@TokenNo, UserID=@UserID, FromDate=@FromDate, ToDate=@ToDate WHERE ID=@ID";
            cmd.Parameters.AddWithValue("@TokenNo", varTokenNo);
            cmd.Parameters.AddWithValue("@UserID", varUserID);
            cmd.Parameters.AddWithValue("@FromDate", varFromDate);
            cmd.Parameters.AddWithValue("@ToDate", varToDate);
            cn.Open();
            cmd.ExecuteNonQuery();
            cn.Close();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号