Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have added below references

C#
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();


Please suggest me What the other references should be added ?.


[Edit]Code is wrapped in "pre" tags[/Edit]
Posted
Updated 19-Apr-11 23:46pm
v3
Comments
Estys 8-Jan-11 10:44am    
Have you set a project reference to the System.Data assembly? Show the context of the errorline.
RaviRanjanKr 8-Jan-11 10:48am    
what error you have got. please mention with error

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


Regards
Espen Harlinn
 
Share this answer
 
Comments
fjdiewornncalwe 8-Jan-11 13:03pm    
Nice and thorough. +5
Espen Harlinn 9-Jan-11 16:43pm    
Thanks Marcus!
Have you included a reference to System.Data.dll under your project References, rather than just adding the relevant using line?
If not, right click on References, and select "Add reference..."
Follow the instructions from there.
 
Share this answer
 
Comments
fjdiewornncalwe 8-Jan-11 13:03pm    
Very relevant response. Just what I was thinking... :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900