jswisher
Posts: 5
|
Posted: 07/26/2010, 7:09 PM |
|
The following is the code. This is what I am trying to do. I am looping through an Excel spreadsheet and loading into the database. With Dao overriden it seems that I have a limited number of options when using the Parameter methods. I received the following error when I run this code. "System.Data.OleDb.OleDbException: Must declare the scalar variable "@Temp_File_Name".
I have working where I just build the SQL string value from the insert statement but I ran into a problem with embeded quotes. It works sort of - I have to drop all quotes out of the data.
Any suggestions would be appreciated.
DataAccessObject NewDao=Settings.newmarkdbDataAccessObject;
string sqlIns = "INSERT INTO TEMP_LEASE (Temp_File_Name,Country,City,State) VALUES (@Temp_File_Name, @Country, @City, @State)";
// string sqlIns = "INSERT INTO TEMP_LEASE (Temp_File_Name,Country,City,State) VALUES (?, ?, ?, ?)";
SqlCommand cmdIns = new SqlCommand(sqlIns, NewDao);
while (odr.Read())
{
country = valid(odr, 1);//Here we are calling the valid method
state = valid(odr, 2);
city = valid(odr, 3);
lstate = valid(odr, 4);
address = valid(odr, 5);
//Here using this method we are inserting the data into the database
cmdIns.Parameters.Add("@Temp_File_Name", filename);
cmdIns.Parameters.Add("@Country", country);
cmdIns.Parameters.Add("@City", city);
cmdIns.Parameters.Add("@State", lstate);
cmdIns.ExecuteNonQuery();
//cmdIns.ExecuteScalar();
}
objConn.Close();
_________________
Jeff Swisher |
|
|
|