Must declare the scalar variable
Hi
I am loading an SQL Table into a table like this:
string commandString2 = "SELECT * FROM [serviceStation]";
DataSet dsServiceStation = new DataSet();
SqlDataAdapter dataAdaptor2 = new
SqlDataAdapter(commandString2, connectionString);
dataAdaptor2.Fill(dsServiceStation, "[serviceStation]"); //
[serviceStation] is the name of the DataTable
Then adding some new rows like this:
foreach (DataRow drServiceStation in dsServiceStation.Tables[0].Rows)
{
if (drServiceStation["stationName"].ToString() ==
mySiteName)
{
blnFound = true;
break;
}
}
if (blnFound == true)
{
// serviceStation record exists - update
}
else
{
// serviceStation record does not exist - add new
DataRow newServiceStation =
dsServiceStation.Tables[0].NewRow();
newServiceStation["stationName"] = mySiteName;
dsServiceStation.Tables[0].Rows.Add(newServiceStation);
}
Then, I try to update the SQL table like this:
string queryString = "INSERT INTO serviceStation
( siteID,codeID,stationName,address1,address2,town,c ounty,postcode,telNo,siteÂTypeID,statusID,salesAr eaID,areaID,brandID,typeID,roadTypeM,roadTypeJ,roa dTÂypeA,roadtypeAB,openHours,costCentre,asset,del iveryPoint,deliveryDepotID,paÂmAreaID,isCurrent,n rvFitted,tanksDetailsID,pumpID,compressorID,cathod icProtÂectionID,siteCount,ERP,shell,telemetryInst alled,temperatureCompensationDtvcÂInstalled,cocaW wcUpgradeInstalled)
VALUES
( @siteID,@codeID,@stationName,@address1,@address2,@ town,@county,@postcode,@tÂelNo,@siteTypeID,@statu sID,@salesAreaID,@areaID,@brandID,@typeID,@roadTyp eMÂ,@roadTypeJ,@roadTypeA,@roadtypeAB,@openHours, @costCentre,@asset,@deliveryPÂoint,@deliveryDepot ID,@pamAreaID,@isCurrent,@nrvFitted,@tanksDetailsI D,@pumÂpID,@compressorID,@cathodicProtectionID,@s iteCount,@ERP,@shell,@telemetryInÂstalled,@temper atureCompensationDtvcInstalled,@cocaWwcUpgradeInst alled)";
dataAdaptor2.InsertCommand = new SqlCommand(queryString,
myDBSQLConnection);
dataAdaptor2.Update(dsServiceStation, "[serviceStation]");
I get an error - Must declare the scalar variable @siteID
What am I doing wrong? It knew the field names in the table in this
line:
if (drServiceStation["stationName"].ToString() == mySiteName)
So they should be present in this line:
dataAdaptor2.Update(dsServiceStation, "[serviceStation]");
|