DELIMITER $$
DROP PROCEDURE IF EXISTS `InsertBookQuest` $$
CREATE PROCEDURE `InsertBookQuest`(
IN pEAN VARCHAR(13),
IN pTitle VARCHAR(255),
IN pRespParty VARCHAR(255),
IN pPublisher VARCHAR(255),
IN pPubDate DATE,
IN pSubject VARCHAR(255),
IN pBinding VARCHAR(45),
IN pPageCount INT,
IN pUSListPrice DECIMAL(19,2),
IN pDemand INT,
IN pOnOrder INT,
IN pOnBackorder INT,
IN pSpeedStock BOOLEAN,
IN pStatus VARCHAR(45),
IN pBTKey INT,
IN pBTFirstPrinting INT,
OUT pIsInsert BOOLEAN
)
BEGIN
DECLARE vCount INT;
SELECT COUNT(1) FROM BookQuest WHERE EAN = pEAN INTO vCount;
IF vCount = 0 THEN
INSERT INTO BookQuest (EAN, Title, RespParty, Publisher, PubDate, `Subject`, Binding, PageCount, USListPrice, Demand, OnOrder, OnBackorder, SpeedStock, `Status`, BTKey, BTFirstPrinting)
VALUES (pEAN, pTitle, pRespParty, pPublisher, pPubDate, pSubject, pBinding, pPageCount, pUSListPrice, pDemand, pOnOrder, pOnBackorder, pSpeedStock, pStatus, pBTKey, pBTFirstPrinting);
SET pIsInsert = 1;
ELSE
UPDATE BookQuest SET Title = pTitle, RespParty = pRespParty, Publisher = pPublisher, PubDate = pPubDate, `Subject` = pSubject, Binding = pBinding, PageCount = pPageCount, Demand = pDemand, OnOrder = pOnOrder, OnBackorder = pOnBackorder, SpeedStock = pSpeedStock, `Status` = pStatus, BTKey = pBTKey, BTFirstPrinting = pBTFirstPrinting
WHERE EAN = pEAN;
SET pIsInsert = 0;
END IF;
END $$
DELIMITER ;
String odbcConnString = WebConfigurationManager.ConnectionStrings["BookList"].ToString();
odbcConnection = new OdbcConnection(odbcConnString);
OdbcCommand odbcCommand = new OdbcCommand("{ CALL Import(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) }", odbcConnection);
odbcCommand.CommandType = CommandType.StoredProcedure;
for (rowCounter = 0; rowCounter < sheetEntries.GetLength(0); rowCounter++)
{
odbcCommand.Parameters.Clear();
OdbcParameter odbcParameter = odbcCommand.Parameters.Add("pEAN", OdbcType.VarChar, 13);
odbcParameter.Value = sheetEntries[rowCounter, 0] == "" ? (object)DBNull.Value : sheetEntries[rowCounter, 0];
odbcParameter = odbcCommand.Parameters.Add("pTitle", OdbcType.VarChar, 255);
odbcParameter.Value = sheetEntries[rowCounter, 1] == "" ? (object)DBNull.Value : sheetEntries[rowCounter, 1];
odbcParameter = odbcCommand.Parameters.Add("pRespParty", OdbcType.VarChar, 255);
odbcParameter.Value = sheetEntries[rowCounter, 2] == "" ? (object)DBNull.Value : sheetEntries[rowCounter, 2];
odbcParameter = odbcCommand.Parameters.Add("pPublisher", OdbcType.VarChar, 255);
odbcParameter.Value = sheetEntries[rowCounter, 3] == "" ? (object)DBNull.Value : sheetEntries[rowCounter, 3];
odbcParameter = odbcCommand.Parameters.Add("pPubDate", OdbcType.SmallDateTime);
odbcParameter.Value = sheetEntries[rowCounter, 4] == "" ? (object)DBNull.Value : Convert.ToDateTime(sheetEntries[rowCounter, 4]);
odbcParameter = odbcCommand.Parameters.Add("pSubject", OdbcType.VarChar, 255);
odbcParameter.Value = sheetEntries[rowCounter, 5] == "" ? (object)DBNull.Value : sheetEntries[rowCounter, 5];
odbcParameter = odbcCommand.Parameters.Add("pBinding", OdbcType.VarChar, 45);
odbcParameter.Value = sheetEntries[rowCounter, 6] == "" ? (object)DBNull.Value : sheetEntries[rowCounter, 6];
odbcParameter = odbcCommand.Parameters.Add("pPageCount", OdbcType.Int);
odbcParameter.Value = sheetEntries[rowCounter, 7] == "" ? (object)DBNull.Value : Convert.ToInt32(sheetEntries[rowCounter, 7]);
odbcParameter = odbcCommand.Parameters.Add("pUSListPrice", OdbcType.Decimal);
odbcParameter.Value = sheetEntries[rowCounter, 8] == "" ? (object)DBNull.Value : Convert.ToDecimal(sheetEntries[rowCounter, 8]);
odbcParameter = odbcCommand.Parameters.Add("pDemand", OdbcType.Int);
odbcParameter.Value = sheetEntries[rowCounter, 9] == "" ? (object)DBNull.Value : Convert.ToInt32(sheetEntries[rowCounter, 9]);
odbcParameter = odbcCommand.Parameters.Add("pOnOrder", OdbcType.Int);
odbcParameter.Value = sheetEntries[rowCounter, 10] == "" ? (object)DBNull.Value : Convert.ToInt32(sheetEntries[rowCounter, 10]);
odbcParameter = odbcCommand.Parameters.Add("pOnBackorder", OdbcType.Int);
odbcParameter.Value = sheetEntries[rowCounter, 11] == "" ? (object)DBNull.Value : Convert.ToInt32(sheetEntries[rowCounter, 11]);
odbcParameter = odbcCommand.Parameters.Add("pSpeedStock", OdbcType.Bit);
if (sheetEntries[rowCounter, 12] == "N" || sheetEntries[rowCounter, 12] == "n")
sheetEntries[rowCounter, 12] = "False";
else if (sheetEntries[rowCounter, 12] == "Y" || sheetEntries[rowCounter, 12] == "y")
sheetEntries[rowCounter, 12] = "True";
odbcParameter.Value = sheetEntries[rowCounter, 12] == "" ? (object)DBNull.Value : Convert.ToBoolean(sheetEntries[rowCounter, 12]);
odbcParameter = odbcCommand.Parameters.Add("pStatus", OdbcType.VarChar, 45);
odbcParameter.Value = sheetEntries[rowCounter, 13] == "" ? (object)DBNull.Value : sheetEntries[rowCounter, 13];
odbcParameter = odbcCommand.Parameters.Add("pBTKey", OdbcType.Int);
odbcParameter.Value = sheetEntries[rowCounter, 14] == "" ? (object)DBNull.Value : Convert.ToInt32(sheetEntries[rowCounter, 14]);
odbcParameter = odbcCommand.Parameters.Add("pBTFirstPrinting", OdbcType.Int);
odbcParameter.Value = sheetEntries[rowCounter, 15] == "" ? (object)DBNull.Value : Convert.ToInt32(sheetEntries[rowCounter, 15]);
odbcParameter = odbcCommand.Parameters.Add("pIsInsert", OdbcType.Bit); // if 1, it is insert, if 0, it is update
odbcCommand.Parameters["pIsInsert"].Direction = ParameterDirection.Output;
if (odbcConnection.State == ConnectionState.Closed)
odbcConnection.Open();
int result = odbcCommand.ExecuteNonQuery();
DROP TABLE IF EXISTS `booklist`.`bookquest`;
CREATE TABLE `booklist`.`bookquest` (
`ID` int(10) unsigned NOT NULL auto_increment COMMENT 'Unique Identifier',
`EAN` varchar(13) NOT NULL COMMENT 'International Article Number',
`Title` varchar(255) NOT NULL,
`RespParty` varchar(255) default NULL,
`Publisher` varchar(255) default NULL,
`PubDate` date default NULL COMMENT 'Publication Date',
`Subject` varchar(255) default NULL,
`Binding` varchar(45) default NULL,
`PageCount` int(10) unsigned default NULL,
`USListPrice` decimal(19,2) default NULL,
`Demand` int(10) unsigned default NULL,
`OnOrder` int(10) unsigned default NULL,
`OnBackorder` int(10) unsigned default NULL,
`SpeedStock` tinyint(1) default NULL,
`Status` varchar(45) default NULL,
`BTKey` int(10) unsigned default NULL,
`FirstPrinting` bigint(20) unsigned default NULL,
`BTFirstPrinting` bigint(20) unsigned default NULL,
`Ingram` varchar(45) default NULL,
`Licensor` varchar(50) default NULL,
`OfferDate` date default NULL,
`LastDate` date default NULL,
`Comments` varchar(255) default NULL,
`Note` varchar(255) default NULL,
`Color` int(10) default NULL,
`FirstAppearance` date default NULL,
`Material` varchar(10) default NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=614366 DEFAULT CHARSET=latin1;
odbcParameter = odbcCommand.Parameters.Add("pSpeedStock", OdbcType.Bit);
if (sheetEntries[rowCounter, 12] == "N" || sheetEntries[rowCounter, 12] == "n") sheetEntries [rowCounter, 12] = "False";
else if (sheetEntries[rowCounter, 12] == "Y" || sheetEntries[rowCounter, 12] == "y") sheetEntries [rowCounter, 12] = "True";
odbcParameter.Value = sheetEntries[rowCounter, 12] == "" ? (object)DBNull.Value : Convert.ToBoolean (sheetEntries[rowCounter, 12]);
if (sheetEntries[rowCounter, 12] == "N" || sheetEntries[rowCounter, 12] == "n")
sheetEntries[rowCounter, 12] = "0";
else if (sheetEntries[rowCounter, 12] == "Y" || sheetEntries[rowCounter, 12] == "y")
sheetEntries[rowCounter, 12] = "1";
odbcParameter.Value = sheetEntries[rowCounter, 12] == "" ? (object)DBNull.Value : Convert.ToInt32(sheetEntries[rowCounter, 12]);
// starting at the top, for clarity...
odbcConnection = new OdbcConnection(odbcConnString);
OdbcCommand odbcCommand = new OdbcCommand("{ CALL InsertBookQuest (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) }", odbcConnection);
odbcCommand.CommandType = CommandType.StoredProcedure;
// parameter setting stuff...modified here to set some local vars for use down below
// example for one var, the rest are left for you
OdbcParameter odbcParameter = odbcCommand.Parameters.Add("pEAN", OdbcType.VarChar, 13);
lvarEAN = sheetEntries[rowCounter, 0] == "" ? (object)DBNull.Value : sheetEntries[rowCounter, 0];
// repeat above for each argument, storing values into local vars.
// resume where you open your connection ...
odbcConnection.Open();
// set the command's activeconnection to point to the connection you just opened
odbcCommand.ActiveConnection = odbcConnection;
// invoke the sp through the connection, supplying a list of the local vars from above
odbcConnection.InsertBookQuest lvarEAN, rest of the local vars you set above goes here;
boolean result = odbcCommand("pIsInsert");
odbcParameter = odbcCommand.Parameters.Add("pBTFirstPrinting", OdbcType.Int);
object BTFirstPrinting = sheetEntries[rowCounter, 15] == "" ? (object)DBNull.Value : Convert.ToInt32(sheetEntries[rowCounter, 15]);
//odbcParameter.Value = sheetEntries[rowCounter, 15] == "" ? (object)DBNull.Value : Convert.ToInt32(sheetEntries[rowCounter, 15]);
odbcParameter = odbcCommand.Parameters.Add("pIsInsert", OdbcType.Bit); // if 1, it is insert, if 0, it is update
odbcCommand.Parameters["pIsInsert"].Direction = ParameterDirection.Output;
Open in new window