C
csharpMind
Guest
I'm pretty new to C# development and I'm trying to update an MS-Access database with my application. When I run my code I get the "No value given for one or more required parameters" error message on my execute statement. Every example I find online tells me that my SQL statement is set up correctly, and I've confirmed that my symbolic parameters actually contain data, so I'm not trying to update my database with empty or null values. Can anyone suggest a course of action for me to correct this problem? Thanks in advance!
private void AddJobsAcconutNumberToNotes()
{
//Create an SQL query string to find all customer names in the Notes table without an account number
String inputString = "SELECT Jobs.Account_Number, Notes.Account_Number, Notes.DisplayID, Jobs.Job_ID " +
"FROM Notes, Jobs " +
"WHERE Jobs.Job_ID = Notes.DisplayId " +
"AND Notes.Account_Number is null " +
"AND Jobs.Account_Number Is Not null ";
try
{
//Convert the SQL query string into database compatible instructions using OleDbCommand,
OleDbCommand cmd = new OleDbCommand(inputString, conn);
OleDbDataReader reader = cmd.ExecuteReader();
//Start reading through the result set
if (reader.HasRows)
{
while (reader.Read())
{
var jobsAccountNumber = reader.GetInt16(0);
var notesDisplayID = reader.GetString(2);
var jobsJobID = reader.GetString(3);
randomCtr++;
this.Text = "AzFloodSquad Maintenance On = " + randomCtr + " Rows";
// No matching contact was found
if (jobsJobID == null)
{
//Do nothing and loop around
}
else
{
var updateQuery = "UPDATE Notes " +
"SET Notes.[Account_Number] = ? " +
"WHERE Jobs.[Job_ID] = ? AND Notes.[DisplayID] = ? ";
var convertedToDbCommands = new OleDbCommand(updateQuery, conn);
convertedToDbCommands.Parameters.AddWithValue("Jobs", jobsAccountNumber);
convertedToDbCommands.Parameters.AddWithValue("Jobs", jobsJobID);
convertedToDbCommands.Parameters.AddWithValue("Notes", notesDisplayID);
//Execute the query
convertedToDbCommands.ExecuteNonQuery(); ERROR OCCURS HERE
}
}
}
}
catch (Exception ex)
{
error_message = ex.Message;
MessageBox.Show(error_message);
}
disconnectToolStripMenuItem.PerformClick();
connectToolStripMenuItem.PerformClick();
MessageBox.Show("The second Notes table account number validation is completed!");
}
Continue reading...
private void AddJobsAcconutNumberToNotes()
{
//Create an SQL query string to find all customer names in the Notes table without an account number
String inputString = "SELECT Jobs.Account_Number, Notes.Account_Number, Notes.DisplayID, Jobs.Job_ID " +
"FROM Notes, Jobs " +
"WHERE Jobs.Job_ID = Notes.DisplayId " +
"AND Notes.Account_Number is null " +
"AND Jobs.Account_Number Is Not null ";
try
{
//Convert the SQL query string into database compatible instructions using OleDbCommand,
OleDbCommand cmd = new OleDbCommand(inputString, conn);
OleDbDataReader reader = cmd.ExecuteReader();
//Start reading through the result set
if (reader.HasRows)
{
while (reader.Read())
{
var jobsAccountNumber = reader.GetInt16(0);
var notesDisplayID = reader.GetString(2);
var jobsJobID = reader.GetString(3);
randomCtr++;
this.Text = "AzFloodSquad Maintenance On = " + randomCtr + " Rows";
// No matching contact was found
if (jobsJobID == null)
{
//Do nothing and loop around
}
else
{
var updateQuery = "UPDATE Notes " +
"SET Notes.[Account_Number] = ? " +
"WHERE Jobs.[Job_ID] = ? AND Notes.[DisplayID] = ? ";
var convertedToDbCommands = new OleDbCommand(updateQuery, conn);
convertedToDbCommands.Parameters.AddWithValue("Jobs", jobsAccountNumber);
convertedToDbCommands.Parameters.AddWithValue("Jobs", jobsJobID);
convertedToDbCommands.Parameters.AddWithValue("Notes", notesDisplayID);
//Execute the query
convertedToDbCommands.ExecuteNonQuery(); ERROR OCCURS HERE
}
}
}
}
catch (Exception ex)
{
error_message = ex.Message;
MessageBox.Show(error_message);
}
disconnectToolStripMenuItem.PerformClick();
connectToolStripMenuItem.PerformClick();
MessageBox.Show("The second Notes table account number validation is completed!");
}
Continue reading...