G
Guest
I am trying to run the following method and keep getting the error "No value
given for one or more required parameters". I've seen that if you have a
field misspelled, that you can get this error, so I ran the query through
Access and it works. Can anyone please tell me what I am doing wrong? The
line it stops on is:
dr = command.ExecuteReader();
Thank you.
public static string Lookup(int customerID)
{
using (OleDbConnection conn = new
OleDbConnection(JimsVideo.Properties.Settings.Default.JimsVideoConnectionString.ToString()))
{
using (OleDbCommand command = new OleDbCommand("SELECT FirstName,
LastName, StreetAddress, StreetAddress2, City, State, Zip, Phone, Phone2,
AccountBalance FROM Customer WHERE CustomerID = ?", conn))
{
conn.Open();
command.Parameters.AddWithValue("customerID", customerID);
OleDbDataReader dr;
dr = command.ExecuteReader();
while (dr.Read())
{
string firstName = dr["FirstName"].ToString();
string lastName = dr["LastName"].ToString();
string streetAddress = dr["StreetAddress"].ToString();
string streetAddress2 = dr["StreetAddress2"].ToString();
string city = dr["City"].ToString();
string state = dr["State"].ToString();
string zip = dr["Zip"].ToString();
string phone = dr["Phone"].ToString();
string phone2 = dr["Phone2"].ToString();
decimal balance = decimal.Parse(dr["AccountBalance"].ToString());
}
return "complete"; //Just for testing until I get this correct.
}
}
}
given for one or more required parameters". I've seen that if you have a
field misspelled, that you can get this error, so I ran the query through
Access and it works. Can anyone please tell me what I am doing wrong? The
line it stops on is:
dr = command.ExecuteReader();
Thank you.
public static string Lookup(int customerID)
{
using (OleDbConnection conn = new
OleDbConnection(JimsVideo.Properties.Settings.Default.JimsVideoConnectionString.ToString()))
{
using (OleDbCommand command = new OleDbCommand("SELECT FirstName,
LastName, StreetAddress, StreetAddress2, City, State, Zip, Phone, Phone2,
AccountBalance FROM Customer WHERE CustomerID = ?", conn))
{
conn.Open();
command.Parameters.AddWithValue("customerID", customerID);
OleDbDataReader dr;
dr = command.ExecuteReader();
while (dr.Read())
{
string firstName = dr["FirstName"].ToString();
string lastName = dr["LastName"].ToString();
string streetAddress = dr["StreetAddress"].ToString();
string streetAddress2 = dr["StreetAddress2"].ToString();
string city = dr["City"].ToString();
string state = dr["State"].ToString();
string zip = dr["Zip"].ToString();
string phone = dr["Phone"].ToString();
string phone2 = dr["Phone2"].ToString();
decimal balance = decimal.Parse(dr["AccountBalance"].ToString());
}
return "complete"; //Just for testing until I get this correct.
}
}
}