No value given for one or more required parameters

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.
}
}
}
 
R

Raghavan Srinath

How? Please let me know



Wannab wrote:

No value given for one or more required parameters
25-Nov-06

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


}

Previous Posts In This Thread:

No value given for one or more required parameters
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


}

RE: No value given for one or more required parameters
Figured it out...thank

:


Submitted via EggHeadCafe - Software Developer Portal of Choice
ASP.NET Providerless Custom Forms Authentication, Roles and Profile with MongoDb
http://www.eggheadcafe.com/tutorial...ntication-roles-and-profile-with-mongodb.aspx
 

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