insert into still does not work?

R

Roy Gourgi

Hi,

Here is my code. I get the error message now that it expects a ")". I have
tried a few different things, but to no avail. What am I doing wrong???? I
can't believe that it is so difficult to add a record in a database. In
Visual Foxpro it's done in one statement. I have tried to install MSDE but
with no luck and that is why I am trying Access. I hope that VS.Net 2005
with SQL express will be easier. This has truly been a nightmare!

Roy


using System;

using System.Data;

using System.Data.OleDb;

using System.Xml.Serialization;

public class MainClass

{

public static void Main ()

{

test.xxx();


}

}



public class test

{

public static void xxx()

{

int lnvar1=10, lnvar2=20, lnvar3=30;

string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=D:\\dbAccess\\db1.mdb";

OleDbConnection myConnection = new OleDbConnection( connectionString );

myConnection.Open();

OleDbCommand myCommand = new OleDbCommand("insert into emp_test (emp_code,
emp_name, emp_ext) VALUES (?, ?,?)", myConnection);

myCommand.Parameters.Add(New SqlCeParameter("emp_code", SqlDbType.NText,
50));

myCommand.Parameters.Add(New SqlCeParameter("emp_name", SqlDbType.NText,
50));

myCommand.Parameters.Add(New SqlCeParameter("emp_ext", SqlDbType.NText,
50));

myCommand.Parameters("emp_code").Value = lnvar1;

myCommand.Parameters("emp_name").Value = lnvar2;

myCommand.Parameters("emp_ext").Value = lnvar3;


myCommand.ExecuteNonQuery();

myConnection.Close();


}

}
 
A

alantolan

1) the 'New' command for each of your parameters should be lower case
not upper. It is not being recognised as a keyword.

2) Very dubious about mix-and-match-ing the OleDB Connection with the
SqlCeParameters.

3) Even if they can be used together, you are missing a 'using' for
System.Data.SqlServerCe.


hth,
Alan.
 
J

Jon Skeet [C# MVP]

Roy Gourgi said:
Here is my code. I get the error message now that it expects a ")".

<snip>

I've replied to your other post already. Please don't repost the same
question in a new thread - it confuses things, as people replying to a
thread are likely to look at all the answers to *that* thread before
replying, but won't check other threads.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top