View Single Post
 
Old August 15th, 2008, 09:42 AM
stapes stapes is offline
Registered User
 
Join Date: May 2008
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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]");