Необходимо объявить скалярную переменную @12
private void btnSave_Click(object sender, EventArgs e) { try { if (txtFirstName.Text == "") { MessageBox.Show("Please enter First Name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtFirstName.Focus(); return; } if (txtLastName.Text == "") { MessageBox.Show("Please enter Last Name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtLastName.Focus(); return; } //if (txtMobileNo.Text == "") //{ // MessageBox.Show("Please enter mobile number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); // txtMobileNo.Focus(); //return; // } cc.con = new SqlConnection(cs.DBCon); cc.con.Open(); string ct = "Select * from StaffMain where StaffCode=@d1"; cc.cmd = new SqlCommand(ct); cc.cmd.Connection = cc.con; cc.cmd.Parameters.AddWithValue("@d1", txtStaffCode.Text); cc.rdr = cc.cmd.ExecuteReader(); if (cc.rdr.Read()) { MessageBox.Show("Staff Code already exit", "", MessageBoxButtons.OK, MessageBoxIcon.Error); txtStaffCode.Text = ""; txtStaffCode.Focus(); if (cc.rdr != null) { cc.con.Close(); } return; } cc.con = new SqlConnection(cs.DBCon); cc.con.Open(); string cb = ("insert into StaffMain(StaffCode,FirstName,LastName,FatherFname,FatherLname,CitizenNo,District,BankAcc,BankName,PermanentAddress,TempAddress,PhoneI,PhoneII,MobileNo,Email,Department,Designation,Groups,Status,Remarks)VALUES(@d1,@d2,@d3,@d4,@d5,@d6,@d7,@d8,@d9,@d10,@d11,@12,@d13,@d14,@d15,@d16,@d17,@d18,@d19,@d20)"); cc.cmd = new SqlCommand(cb); cc.cmd.Connection = cc.con; cc.cmd.Parameters.AddWithValue("@d1", txtStaffCode.Text); cc.cmd.Parameters.AddWithValue("@d2", txtFirstName.Text); cc.cmd.Parameters.AddWithValue("@d3", txtLastName.Text); cc.cmd.Parameters.AddWithValue("@d4", txtFatherFname.Text); cc.cmd.Parameters.AddWithValue("@d5", txtFatherLname.Text); cc.cmd.Parameters.AddWithValue("@d6", txtCitizen.Text); cc.cmd.Parameters.AddWithValue("@d7", cmbDistrict.Text); cc.cmd.Parameters.AddWithValue("@d8", txtBankAcc.Text); cc.cmd.Parameters.AddWithValue("@d9", cmbBankName.Text); cc.cmd.Parameters.AddWithValue("@d10", txtPermanentAddress.Text); cc.cmd.Parameters.AddWithValue("@d11", txtTemporaryAddress.Text); cc.cmd.Parameters.AddWithValue("@d12", txtPhoneI.Text); cc.cmd.Parameters.AddWithValue("@d13", txtPhoneII.Text); cc.cmd.Parameters.AddWithValue("@d14", txtMobileNo.Text); cc.cmd.Parameters.AddWithValue("@d15", txtEmailID.Text); cc.cmd.Parameters.AddWithValue("@d16", txtDepartment.Text); cc.cmd.Parameters.AddWithValue("@d17", txtDesiganation.Text); cc.cmd.Parameters.AddWithValue("@d18", txtGroup.Text); cc.cmd.Parameters.AddWithValue("@d19", cmbStatus.Text); cc.cmd.Parameters.AddWithValue("@d20", txtRemarks.Text); cc.cmd.ExecuteReader(); cc.con.Close(); st1 = lblUser.Text; st2 = "Added the new Staff having StaffCode'" + txtStaffCode.Text + "'"; MessageBox.Show("Data Added Successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
[edit]добавлен блок кода-OriginalGriff [/edit]
Что я уже пробовал:
необходимо объявить скалярную переменную