August 8, 2005 at 9:12 am
Hi for all
In my MS Access, when I perfom a insert operation, the folling message is showed:
"Any value has provided for one or more needed parameters"
I'm inserting values with a method created in C#. Below the method:
public void InsertNewArtist(string sNomCD)
{
string sInsert = "insert into Artistas (nome_cd)" + "values(sNomCD)";
try
{
OleDbConnection OleConnect = new OleDbConnection(m_sConnection);
OleDbCommand OleCommand = new OleDbCommand(sInsert, OleConnect);
OleCommand.Connection.Open();
OleCommand.ExecuteNonQuery();
OleConnect.Close();
}
catch(OleDbException ex)
{
MessageBox.Show(ex.Message);
}
}
My connection string:
private string m_sConnection = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Alex Cutovoi\Meus documentos\CDS.mdb;" + @"User ID = Admin;Password=";
I think that the connection is correct. So, what's going on?
Thanks a lot
August 8, 2005 at 12:08 pm
Can you check the column name of the insert table. Most likely, the column name does not match.
But I may be wrong...
August 9, 2005 at 2:00 am
Shouldn't this
"insert into Artistas (nome_cd)" + "values(sNomCD)"
be
"insert into Artistas (nome_cd) values('" + sNomCD + "')"
You are inserting the string sNomCD and not the contents of that variable and it should be in single quotes cos its a string?
August 9, 2005 at 6:32 am
I have to agree. You have not concatenated the string that was passed into the function. As a general rule, it is best to print your sql strings to the screen to make sure you are getting what you expect. it takes only a moment but saves a lot of time. I know this from experience.
Kindest Regards,
David
** Obstacles are those frightening things that appear when we take our eyes off the goal. **
August 9, 2005 at 6:37 am
Even better to use stored procs .
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply