PDA

View Full Version : مشكل در INSERT كردن در OLEDB DATABASE



jalalx
جمعه 07 فروردین 1388, 20:13 عصر
با سلام خدمت دوستان!
من يه مشكل عجيب در INSERT كردن دارم! گاهي هنگامي كه ديبا گريد رو بعد از INSERT و FILL كردن ديتاست refresh مي كنم دو تا ركورد به جاي يك ركورد در جدول رايانه ها مي بينم!!!

من اين INSERT رو در دو جدول Hardwares و Computers انجام ميدم.



void AddComputer()
{
OleDbCommand INSERT = new OleDbCommand();
object index;
ComputerFormDialog frmComputer = new ComputerFormDialog();
if (frmComputer.ShowDialog() == DialogResult.OK)
{
INSERT.Connection = new OleDbConnection(Properties.Settings.Default.Report erConnectionString);
INSERT.CommandType = CommandType.StoredProcedure;
INSERT.CommandText = "AddComputer";
INSERT.Parameters.AddWithValue("@Monitor", frmComputer.monitorTextEdit.Text);
INSERT.Parameters.AddWithValue("@HDD", frmComputer.hDDTextEdit.Text);
INSERT.Parameters.AddWithValue("@Graphic", frmComputer.graphicTextEdit.Text);
INSERT.Parameters.AddWithValue("@RAM", frmComputer.rAMTextEdit.Text);
INSERT.Parameters.AddWithValue("@Power", frmComputer.powerTextEdit.Text);
INSERT.Parameters.AddWithValue("@CPU", frmComputer.cPUTextEdit.Text);
INSERT.Parameters.AddWithValue("@Motherboard", frmComputer.motherboardTextEdit.Text);
INSERT.Parameters.AddWithValue("@CDROM", frmComputer.cDROMTextEdit.Text);
INSERT.Parameters.AddWithValue("@DVDROM", frmComputer.dVDROMTextEdit.Text);
INSERT.Parameters.AddWithValue("@IP", frmComputer.iPTextEdit.Text);
INSERT.Parameters.AddWithValue("@ComputerName", frmComputer.computerNameTextEdit.Text);
INSERT.Parameters.AddWithValue("@Case", frmComputer.caseTextEdit.Text);
INSERT.Connection.Open();
INSERT.ExecuteNonQuery();
INSERT.Connection.Close();
INSERT = null;
//Get last current computer's ID...
INSERT = new OleDbCommand();
INSERT.Connection = new OleDbConnection(Properties.Settings.Default.Report erConnectionString);
INSERT.CommandType = CommandType.Text;
INSERT.CommandText = "SELECT MAX(ID) FROM Computers";
INSERT.Connection.Open();
index = INSERT.ExecuteScalar();
INSERT.Connection.Close();
INSERT = null;
//Adding hardwares record...
INSERT = new OleDbCommand();
INSERT.Connection = new OleDbConnection(Properties.Settings.Default.Report erConnectionString);
INSERT.CommandType = CommandType.StoredProcedure;
INSERT.CommandText = "AddHardware";
INSERT.Parameters.AddWithValue("@Lable", frmComputer.lableTextEdit.Text);
INSERT.Parameters.AddWithValue("@Unit", frmComputer.unitTextEdit.Text);
INSERT.Parameters.AddWithValue("@Operator", frmComputer.operatorTextEdit.Text);
INSERT.Parameters.AddWithValue("@BuyDate", frmComputer.buyDateTextEdit.Text);
INSERT.Parameters.AddWithValue("@HardwareType", "كامپيوتر");
INSERT.Parameters.AddWithValue("@HardwareID", index);
INSERT.Connection.Open();
INSERT.ExecuteNonQuery();
INSERT.Connection.Close();
}
INSERT.Dispose();
frmComputer.Dispose();
}