.net 2.0和C# - 我使用存储过程将行插入到mysql中,但是当我尝试同时从两个客户端插入数据时,我发现只插入了一行而不是两者。我无法得到错误。如何调整数据库或我的代码以插入所有数据,并且不会感谢线程
这是我的表
delimiter $$
CREATE TABLE `tblemployee` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`EmpID` int(11) NOT NULL,
`FedTaxID` varchar(9) CHARACTER SET utf8 NOT NULL,
`FirstName` varchar(20) DEFAULT NULL,
`MiddleInitial` varchar(20) DEFAULT NULL,
`LastName` varchar(20) DEFAULT NULL,
`SSN` decimal(9,0) NOT NULL,
`DateOfBirth` varchar(50) CHARACTER SET utf8 DEFAULT NULL,
`MaritalTypeID` varchar(4) CHARACTER SET utf8 DEFAULT NULL,
`EmployeeTypeID` varchar(1) CHARACTER SET utf8 DEFAULT NULL,
`EmploymentStatusTypeID` varchar(1) CHARACTER SET utf8 DEFAULT NULL,
`HireDate` varchar(50) CHARACTER SET utf8 DEFAULT NULL,
`EmployeeWorkLocation` varchar(30) CHARACTER SET utf8 DEFAULT NULL,
`RegularPay` double DEFAULT NULL,
`HourlyRate` double DEFAULT NULL,
`OtherHoursRate` double DEFAULT NULL,
`StartDate` date NOT NULL,
`EndDate` date NOT NULL,
`PayFrequencyTypeID` varchar(50) DEFAULT NULL,
PRIMARY KEY (`EmpID`,`FedTaxID`),
UNIQUE KEY `SSN_UNIQUE` (`SSN`),
KEY `id` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=385 DEFAULT CHARSET=latin1$$
这是我的存储过程:
CREATE DEFINER=`root`@`%` PROCEDURE `uspEmployeeAdd`(_EmpID int,_FedTaxID varchar(9),_SSN decimal(9,0),_DateOfBirth varchar(50),_MaritalTypeID varchar(2),_EmployeeTypeID varchar(1),_EmploymentStatusTypeID varchar(1),_HireDate varchar(50),_EmployeeWorkLocation varchar(30),_PayFrequencyType varchar(2),_RegularPay double,_HourlyRate double,_OtherHoursRate double)
BEGIN
insert delayed into tblEmployee(EmpID, FedTaxID, SSN, DateOfBirth, MaritalTypeID, EmployeeTypeID, EmploymentStatusTypeID, HireDate, EmployeeWorkLocation, PayFrequencyType, RegularPay, HourlyRate, OtherHoursRate)
values(_EmpID, _FedTaxID, _SSN, _DateOfBirth, _MaritalTypeID, _EmployeeTypeID, _EmploymentStatusTypeID, _HireDate, _EmployeeWorkLocation, _PayFrequencyType, _RegularPay, _HourlyRate, _OtherHoursRate);
END
这里是我的.net代码
public bool Adding()
{
m_bFlag = false;
if (m_oConn.State != ConnectionState.Open)
{
m_oConn.Open();
}
MySqlTransaction otrans = new MySqlTransaction();
otrans=m_oConn.BeginTransaction();
m_oCmd = new MySqlCommand(StoredProcNames.EmployeeDetails_uspEmployeeDetailsInsert, m_oConn);
m_oCmd.CommandType = CommandType.StoredProcedure;
m_oCmd.Parameters.AddWithValue("_EmpID", EmpID);
m_oCmd.Parameters.AddWithValue("_FedTaxID", FedTaxID);
m_oCmd.Parameters.AddWithValue("_FirstName", FirstName);
m_oCmd.Parameters.AddWithValue("_MiddleInitial", MiddleInitial);
m_oCmd.Parameters.AddWithValue("_LastName", LastName);
m_oCmd.Parameters.AddWithValue("_SSN", SSN);
m_oCmd.Parameters.AddWithValue("_MaritalTypeID", Gender);
m_oCmd.Parameters.AddWithValue("_HireDate", HireDate);
m_oCmd.Parameters.AddWithValue("_DateOfBirth", DateOfBirth);
m_oCmd.Parameters.AddWithValue("_PayFrequencyTypeID", PayFrequencyTypeID);
m_oCmd.Parameters.AddWithValue("_StartDate", StartDate);
m_oCmd.Parameters.AddWithValue("_EndDate", EndDate);
try
{
if (m_oCmd.ExecuteNonQuery() > 0)
{
m_bFlag = true;
otrans.Commit();
}
}
catch (MySqlException mse)
{
throw mse;
otrans.Rollback();
}
finally
{
m_oConn.Close();
}
return this.m_bFlag;
}