小编mep*_*epk的帖子

如何使用oledb将记录插入访问表?

我在ms访问中有一个这个Items表

Items(Table)    
Item_Id(autonumber)
Item_Name(text)
Item_Price(currency)
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用此代码插入记录.

OleDbConnection myCon = new OleDbConnection(ConfigurationManager.ConnectionStrings["DbConn"].ToString());
        OleDbCommand cmd = new OleDbCommand();
        cmd.CommandType = CommandType.Text;
        cmd.CommandText = "insert into Items ([Item_Name],[Item_Price]) values ('" + itemNameTBox.Text + "','" + Convert.ToDouble(itemPriceTBox.Text) + "')";
        cmd.Connection = myCon;
        myCon.Open();
        cmd.ExecuteNonQuery();
        System.Windows.Forms.MessageBox.Show("An Item has been successfully added", "Caption", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
        myCon.Close();
Run Code Online (Sandbox Code Playgroud)

代码运行没有错误,但最后在表中没有记录我正在做什么错误?

c# ms-access winforms

9
推荐指数
1
解决办法
5万
查看次数

标签 统计

c# ×1

ms-access ×1

winforms ×1