[已解决]使用OleDB命令对象时出错 [英] [Solved] Error while using OleDB command object
本文介绍了[已解决]使用OleDB命令对象时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在下面添加了参考文献
I have added below references
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data.Common;
我在代码中使用了下面的代码.这给了我错误.
I have used below line in my code . which gave me error.
OleDbCommand Com = new OleDbCommand();
请建议我,还应添加哪些其他参考?.
[Edit]代码包装在"pre"标签中[/Edit]
Please suggest me What the other references should be added ?.
Code is wrapped in "pre" tags[/Edit]
推荐答案
您需要创建一个 ^ ]对象
You need to create a connection[^] object
public void InsertRow(string myConnectionString)
{
// If the connection string is null, use a default.
if(myConnectionString == "")
{
myConnectionString = "Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=Northwind;" +
"Integrated Security=SSPI;quot;;
}
OleDbConnection myConnection = new OleDbConnection(myConnectionString);
string myInsertQuery = "INSERT INTO Customers (CustomerID, CompanyName) Values(''NWIND'', ''Northwind Traders'')";
OleDbCommand myCommand = new OleDbCommand(myInsertQuery);
myCommand.Connection = myConnection;
myConnection.Open();
myCommand.ExecuteNonQuery();
myCommand.Connection.Close();
}
问候
Espen Harlinn
Regards
Espen Harlinn
您是否在项目引用"下包含了对System.Data.dll的引用,而不仅仅是添加了相关的using
行?
如果不是,请右键单击引用",然后选择添加引用..."
请按照那里的说明进行操作.
Have you included a reference to System.Data.dll under your project References, rather than just adding the relevantusing
line?
If not, right click on References, and select "Add reference..."
Follow the instructions from there.
这篇关于[已解决]使用OleDB命令对象时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文