Ошибка при поиске записи с помощью C#
Спасибо, парень.
Я отредактировал программу в соответствии с рекомендациями(пожалуйста, смотрите приведенный ниже код для отредактированной версии), ошибка исчезла, и появилась еще одна ошибка " нет записи: строка не была распознана как действительное время. Существует неизвестное слово, начинающееся с индекса 0. Буду признателен за любую помощь
Что я уже пробовал:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; using System.Configuration; using System.IO; namespace FHAMortgageBank { public partial class Add_Employee : Form { public Add_Employee() { InitializeComponent(); ClearData();// Method FillBank(); FillStatus(); FillPenAdmin(); FillYear(); FillGrade(); FillDpt(); New_Rec(); DisplayData(); New_Rec(); } public static string constring = "Data Source=AKINTOMIDE-HP\\SQLEXPRESS;Initial Catalog=fham;Integrated Security=True"; SqlConnection con = new SqlConnection("Data Source=AKINTOMIDE-HP\\SQLEXPRESS;Initial Catalog=fham;Integrated Security=True"); SqlCommand cmd; //SqlDataAdapter adapt; SqlDataReader dreader; SqlDataAdapter adapt = new SqlDataAdapter(); private DataViewManager dviewmanager; int SN = 0; private void frmMain_Enter(object sender, EventArgs e) { } private void picStafPix_Click(object sender, EventArgs e) { //this.picStafPix.Image = Image.FromFile(@"Images\a.bmp"); } private void button1_Click(object sender, EventArgs e) { // open file dialog OpenFileDialog open = new OpenFileDialog(); // image filters open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp"; if (open.ShowDialog() == DialogResult.OK) { // display image in picture box this.picStafPix.Image = new Bitmap(open.FileName); // image file path textBox1.Text = open.FileName; } } //public frmMain() //{ //} private void BntSave_Click(object sender, EventArgs e) { //if (txteid.Text != "" && txtStaf.Text != "") //{ // MessageBox.Show("Please enter valid data..."); //} //else if (textBox1.Text == "") { MessageBox.Show("Please enter valid data..."); } else { FileStream fs = new FileStream(textBox1.Text, FileMode.OpenOrCreate, FileAccess.Read); byte[] bt = new byte[fs.Length]; fs.Read(bt, 0, System.Convert.ToInt32(fs.Length)); fs.Close(); // System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(); //cmd.CommandType = System.Data.CommandType.Text; SqlConnection con = new SqlConnection(); con.ConnectionString = "Data Source=AKINTOMIDE-HP\\SQLEXPRESS;Initial Catalog=fham;Integrated Security=True"; cmd = new SqlCommand("insert into master (eid,mon,yr,dat,staf,adrs,coy,loc,dpt,grd,datead,datemod,bsal,[tran],hous,lunc,uti,furn,harz,educ,housM,dres,risk,veh,driv,dome,pfs,nhf,nhfs,oded,housU,staffM,thrift,otherP,accno,bank,email,penadmin,pennum,status,dupfront,picstaffpix,pens,paye,tded,tpay,npay) values(@eid, @mon,@yr,@dat,@staf,@adrs,@coy,@loc,@dpt,@grd,@datead,@datemod,@bsal,@tran,@hous,@lunc,@uti,@furn,@harz,@educ,@housM,@dres,@risk,@veh,@driv,@dome,@pfs,@nhf,@nhfs,@oded,@housU,@staffM,@thrift,@otherP,@accno,@bank,@email,@penadmin,@pennum,@status,@dupfront,@picstaffpix,@pens,@paye,@tded,@tpay,@npay)", con); con.Open(); cmd.Parameters.AddWithValue("@eid", txteid.Text); cmd.Parameters.AddWithValue("@yr", cmbYr.Text); cmd.Parameters.AddWithValue("@dat", datAd.Text); cmd.Parameters.AddWithValue("@datead", datEmp.Text); cmd.Parameters.AddWithValue("@datemod", DatMod.Text); cmd.Parameters.AddWithValue("@staf", txtStaf.Text); cmd.Parameters.AddWithValue("@adrs", txtAdrs.Text); cmd.Parameters.AddWithValue("@coy", txtCoy.Text); cmd.Parameters.AddWithValue("@dpt", cmbDpt.Text); cmd.Parameters.AddWithValue("@loc", cmbLoc.Text); cmd.Parameters.AddWithValue("@grd", CmbGrd.Text); cmd.Parameters.AddWithValue("@accno", TxtAccno.Text); cmd.Parameters.AddWithValue("@email", txtemail.Text); cmd.Parameters.AddWithValue("@picstaffpix", bt); // cmd.Parameters.AddWithValue("@picstaffpix", this.picStafPix.Image); cmd.Parameters.AddWithValue("@bank", cmbBank.Text); cmd.Parameters.AddWithValue("@penadmin", cmbPenAdmin.Text); cmd.Parameters.AddWithValue("@status", cmbStatus.Text); cmd.Parameters.AddWithValue("@pennum", txtPenNum.Text); cmd.Parameters.AddWithValue("@bsal", txtBSal.Text); cmd.Parameters.AddWithValue("@dres", txtDres.Text); cmd.Parameters.AddWithValue("@dupfront", txtDUpfront.Text); cmd.Parameters.AddWithValue("@educ", txtEduc.Text); cmd.Parameters.AddWithValue("@furn", txtFurn.Text); cmd.Parameters.AddWithValue("@harz", txtHarz.Text); cmd.Parameters.AddWithValue("@tran", txtTran.Text); cmd.Parameters.AddWithValue("@hous", txtHous.Text); cmd.Parameters.AddWithValue("@lunc", txtLunc.Text); cmd.Parameters.AddWithValue("@uti", txtUti.Text); cmd.Parameters.AddWithValue("@housM", txtHousM.Text); cmd.Parameters.AddWithValue("@risk", txtRisk.Text); cmd.Parameters.AddWithValue("@veh", txtVeh.Text); cmd.Parameters.AddWithValue("@pfs", txtPfS.Text); cmd.Parameters.AddWithValue("@nhf", txtNHF.Text); cmd.Parameters.AddWithValue("@nhfs", txtNHFS.Text); cmd.Parameters.AddWithValue("@oded", txtOded.Text); cmd.Parameters.AddWithValue("@pens", txtPens.Text); cmd.Parameters.AddWithValue("@paye", this.txtPAYE.Text); cmd.Parameters.AddWithValue("@tded", txtTDed.Text); cmd.Parameters.AddWithValue("@driv", txtDriv.Text); cmd.Parameters.AddWithValue("@dome", txtDome.Text); cmd.Parameters.AddWithValue("@tpay", txtTPay.Text); cmd.Parameters.AddWithValue("@npay", txtNPay.Text); cmd.Parameters.AddWithValue("@housU", this.txtHousU.Text); cmd.Parameters.AddWithValue("@staffM", this.txtStaffM.Text); cmd.Parameters.AddWithValue("@thrift", this.txtThrift.Text); cmd.Parameters.AddWithValue("@mon", cmbMon.Text); cmd.Parameters.AddWithValue("@otherP", this.txtOtherPay.Text); cmd.Parameters.AddWithValue("@photo", this.textBox1.Text); cmd.Parameters.AddWithValue("@BrowsePic", this.button1.Text); cmd.Connection = con; try { int k = cmd.ExecuteNonQuery(); MessageBox.Show("Saved..."); ClearData();// Method // textBox1.Text = ""; } catch (Exception ex) { MessageBox.Show("Not Save:\n" + ex.Message); } finally { con.Close(); } } } private void btnUpdate_Click(object sender, EventArgs e) { //if (txteid.Text != "" && txtStaf.Text != "") //{ // MessageBox.Show("Please enter valid data..."); //} //else if (textBox1.Text == "") { MessageBox.Show("Please enter valid data..."); } else { FileStream fs = new FileStream(textBox1.Text, FileMode.OpenOrCreate, FileAccess.Read); byte[] bt = new byte[fs.Length]; fs.Read(bt, 0, System.Convert.ToInt32(fs.Length)); fs.Close(); System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(); cmd.CommandType = System.Data.CommandType.Text; SqlDataAdapter adapt = new SqlDataAdapter(); SqlConnection con = new SqlConnection(); con.ConnectionString = "Data Source=AKINTOMIDE-HP\\SQLEXPRESS;Initial Catalog=fham;Integrated Security=True"; cmd = new SqlCommand("update master set mon=@Mon , yr=@Yr, dat=@dat,staf=@Staf,adrs=@Adrs,coy=@Coy,loc=@Loc,dpt=@Dpt,grd= @Grd,datead=@datead,datemod=@datemod,bsal=@BSal,[tran]=@Tran,hous=@Hous,lunc=@Lunc,uti=@Uti,furn=@Furn,harz=@Harz,educ=@Educ,housM=@HousM,dres=@Dres,risk=@Risk,veh=@Veh,driv=@Driv,dome=@Dome,pfs=@PfS,nhf=@NHF,nhfs=@NHFS,oded=@Oded,housU=@HousU,staffM=@StaffM,thrift=@Thrift,accno=@Accno,bank= @Bank,email=@email,penadmin=@PenAdmin,pennum=@PenNum,status=@Status,dupfront=@DUpfront,picstaffpix=@picstaffpix,pens=@Pens,paye=@PAYE,Tpay=@TPay,npay=@NPay WHERE eid= @eid ", con); con.Open(); cmd.Parameters.AddWithValue("@eid", txteid.Text); cmd.Parameters.AddWithValue("@yr", cmbYr.Text); cmd.Parameters.AddWithValue("@dat", datAd.Text); cmd.Parameters.AddWithValue("@datead", datEmp.Text); cmd.Parameters.AddWithValue("@datemod", DatMod.Text); cmd.Parameters.AddWithValue("@staf", txtStaf.Text); cmd.Parameters.AddWithValue("@adrs", txtAdrs.Text); cmd.Parameters.AddWithValue("@coy", txtCoy.Text); cmd.Parameters.AddWithValue("@dpt", cmbDpt.Text); cmd.Parameters.AddWithValue("@loc", cmbLoc.Text); cmd.Parameters.AddWithValue("@grd", CmbGrd.Text); cmd.Parameters.AddWithValue("@accno", TxtAccno.Text); cmd.Parameters.AddWithValue("@email", txtemail.Text); cmd.Parameters.AddWithValue("@picstaffpix", bt); //cmd.Parameters.AddWithValue("@picstaffpix", this.picStafPix.Image); cmd.Parameters.AddWithValue("@bank", cmbBank.Text); cmd.Parameters.AddWithValue("@penadmin", cmbPenAdmin.Text); cmd.Parameters.AddWithValue("@status", cmbStatus.Text); cmd.Parameters.AddWithValue("@pennum", txtPenNum.Text); cmd.Parameters.AddWithValue("@bsal", txtBSal.Text); cmd.Parameters.AddWithValue("@dres", txtDres.Text); cmd.Parameters.AddWithValue("@dupfront", txtDUpfront.Text); cmd.Parameters.AddWithValue("@educ", txtEduc.Text); cmd.Parameters.AddWithValue("@furn", txtFurn.Text); cmd.Parameters.AddWithValue("@harz", txtHarz.Text); cmd.Parameters.AddWithValue("@tran", txtTran.Text); cmd.Parameters.AddWithValue("@hous", txtHous.Text); cmd.Parameters.AddWithValue("@lunc", txtLunc.Text); cmd.Parameters.AddWithValue("@uti", txtUti.Text); cmd.Parameters.AddWithValue("@housM", txtHousM.Text); cmd.Parameters.AddWithValue("@risk", txtRisk.Text); cmd.Parameters.AddWithValue("@veh", txtVeh.Text); cmd.Parameters.AddWithValue("@pfs", txtPfS.Text); cmd.Parameters.AddWithValue("@nhf", txtNHF.Text); cmd.Parameters.AddWithValue("@nhfs", txtNHFS.Text); cmd.Parameters.AddWithValue("@oded", txtOded.Text); cmd.Parameters.AddWithValue("@pens", txtPens.Text); cmd.Parameters.AddWithValue("@paye", this.txtPAYE.Text); cmd.Parameters.AddWithValue("@tded", txtTDed.Text); cmd.Parameters.AddWithValue("@driv", txtDriv.Text); cmd.Parameters.AddWithValue("@dome", txtDome.Text); cmd.Parameters.AddWithValue("@tpay", txtTPay.Text); cmd.Parameters.AddWithValue("@npay", txtNPay.Text); cmd.Parameters.AddWithValue("@housU", this.txtHousU.Text); cmd.Parameters.AddWithValue("@staffM", this.txtStaffM.Text); cmd.Parameters.AddWithValue("@thrift", this.txtThrift.Text); cmd.Parameters.AddWithValue("@mon", cmbMon.Text); cmd.Parameters.AddWithValue("@otherP", this.txtOtherPay.Text); cmd.Parameters.AddWithValue("@photo", this.textBox1.Text); cmd.Parameters.AddWithValue("@BrowsePic", this.button1.Text); adapt.UpdateCommand = cmd; cmd.Connection = con; try { int k = cmd.ExecuteNonQuery(); MessageBox.Show("Updated..."); ClearData();// Method //textBox1.Text = ""; } catch (Exception ex) { MessageBox.Show("Not Updated:\n" + ex.Message); } finally { con.Close(); } } } private void btnSearch_Click(object sender, EventArgs e) { // if (txteid.Text != "" && txtStaf.Text != "") //{ // MessageBox.Show("Please enter valid data..."); //} //else if (textBox1.Text == "") { } else { FileStream fs = new FileStream(textBox1.Text, FileMode.OpenOrCreate, FileAccess.Read); byte[] bt = new byte[fs.Length]; fs.Read(bt, 0, System.Convert.ToInt32(fs.Length)); fs.Close(); SqlConnection con = new SqlConnection(); //System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(); //cmd.CommandType = System.Data.CommandType.Text; //SqlDataAdapter adapt = new SqlDataAdapter(); con.ConnectionString = "Data Source=AKINTOMIDE-HP\\SQLEXPRESS;Initial Catalog=fham;Integrated Security=True"; //SqlCommand cmd = new SqlCommand("delete master where txteid.Text =@eid", con); cmd = new SqlCommand("select * from master where eid =@eid", con); con.Open(); cmd.Parameters.AddWithValue("@eid", txteid.Text); //cmd.Parameters.AddWithValue("@yr", cmbYr.Text); //cmd.Parameters.AddWithValue("@dat", datAd.Text); //cmd.Parameters.AddWithValue("@datead", datEmp.Text); //cmd.Parameters.AddWithValue("@datemod", DatMod.Text); //cmd.Parameters.AddWithValue("@staf", txtStaf.Text); //cmd.Parameters.AddWithValue("@adrs", txtAdrs.Text); //cmd.Parameters.AddWithValue("@coy", txtCoy.Text); //cmd.Parameters.AddWithValue("@dpt", cmbDpt.Text); //cmd.Parameters.AddWithValue("@loc", cmbLoc.Text); //cmd.Parameters.AddWithValue("@grd", CmbGrd.Text); //cmd.Parameters.AddWithValue("@accno", TxtAccno.Text); //cmd.Parameters.AddWithValue("@email", txtemail.Text); //cmd.Parameters.AddWithValue("@picstaffpix", bt); //cmd.Parameters.AddWithValue("@bank", cmbBank.Text); //cmd.Parameters.AddWithValue("@penadmin", cmbPenAdmin.Text); //cmd.Parameters.AddWithValue("@status", cmbStatus.Text); //cmd.Parameters.AddWithValue("@pennum", txtPenNum.Text); //cmd.Parameters.AddWithValue("@bsal", txtBSal.Text); //cmd.Parameters.AddWithValue("@dres", txtDres.Text); //cmd.Parameters.AddWithValue("@dupfront", txtDUpfront.Text); //cmd.Parameters.AddWithValue("@educ", txtEduc.Text); //cmd.Parameters.AddWithValue("@furn", txtFurn.Text); //cmd.Parameters.AddWithValue("@harz", txtHarz.Text); //cmd.Parameters.AddWithValue("@tran", txtTran.Text); //cmd.Parameters.AddWithValue("@hous", txtHous.Text); //cmd.Parameters.AddWithValue("@lunc", txtLunc.Text); //cmd.Parameters.AddWithValue("@uti", txtUti.Text); //cmd.Parameters.AddWithValue("@housM", txtHousM.Text); //cmd.Parameters.AddWithValue("@risk", txtRisk.Text); //cmd.Parameters.AddWithValue("@veh", txtVeh.Text); //cmd.Parameters.AddWithValue("@pfs", txtPfS.Text); //cmd.Parameters.AddWithValue("@nhf", txtNHF.Text); //cmd.Parameters.AddWithValue("@nhfs", txtNHFS.Text); //cmd.Parameters.AddWithValue("@oded", txtOded.Text); //cmd.Parameters.AddWithValue("@pens", txtPens.Text); //cmd.Parameters.AddWithValue("@paye", this.txtPAYE.Text); //cmd.Parameters.AddWithValue("@tded", txtTDed.Text); //cmd.Parameters.AddWithValue("@driv", txtDriv.Text); //cmd.Parameters.AddWithValue("@dome", txtDome.Text); //cmd.Parameters.AddWithValue("@tpay", txtTPay.Text); //cmd.Parameters.AddWithValue("@npay", txtNPay.Text); //cmd.Parameters.AddWithValue("@housU", this.txtHousU.Text); //cmd.Parameters.AddWithValue("@staffM", this.txtStaffM.Text); //cmd.Parameters.AddWithValue("@thrift", this.txtThrift.Text); //cmd.Parameters.AddWithValue("@mon", cmbMon.Text); //cmd.Parameters.AddWithValue("@otherP", this.txtOtherPay.Text); //cmd.Parameters.AddWithValue("@photo", this.textBox1.Text); //cmd.Parameters.AddWithValue("@BrowsePic", this.button1.Text); cmd.Connection = con; try { dreader = cmd.ExecuteReader(); if (dreader.Read()) { //txtname.Text = dreader[1].ToString(); txteid.Text = dreader[1].ToString(); cmbYr.Text = dreader[2].ToString(); datAd.Text = dreader[3].ToString(); datEmp.Text = dreader[4].ToString(); DatMod.Text = dreader[5].ToString(); txtStaf.Text = dreader[6].ToString(); txtAdrs.Text = dreader[7].ToString(); txtCoy.Text = dreader[8].ToString(); cmbDpt.Text = dreader[9].ToString(); cmbLoc.Text = dreader[10].ToString(); CmbGrd.Text = dreader[11].ToString(); TxtAccno.Text = dreader[12].ToString(); txtemail.Text = dreader[13].ToString(); // bt=dreader[14].ToString(); cmbBank.Text = dreader[15].ToString(); cmbPenAdmin.Text = dreader[16].ToString(); cmbStatus.Text = dreader[17].ToString(); txtPenNum.Text = dreader[18].ToString(); txtBSal.Text = dreader[19].ToString(); txtDres.Text = dreader[20].ToString(); txtDUpfront.Text = dreader[21].ToString(); txtEduc.Text = dreader[22].ToString(); txtFurn.Text = dreader[23].ToString(); txtHarz.Text = dreader[24].ToString(); txtTran.Text = dreader[25].ToString(); txtHous.Text = dreader[26].ToString(); txtLunc.Text = dreader[27].ToString(); txtUti.Text = dreader[28].ToString(); txtHousM.Text = dreader[29].ToString(); txtRisk.Text = dreader[30].ToString(); txtVeh.Text = dreader[31].ToString(); txtPfS.Text = dreader[32].ToString(); txtNHF.Text = dreader[33].ToString(); txtNHFS.Text = dreader[34].ToString(); txtOded.Text = dreader[35].ToString(); txtPens.Text = dreader[36].ToString(); txtPAYE.Text = dreader[37].ToString(); txtTDed.Text = dreader[38].ToString(); txtDriv.Text = dreader[39].ToString(); txtDome.Text = dreader[40].ToString(); txtTPay.Text = dreader[41].ToString(); txtNPay.Text = dreader[42].ToString(); txtHousU.Text = dreader[43].ToString(); txtStaffM.Text = dreader[44].ToString(); txtThrift.Text = dreader[45].ToString(); cmbMon.Text = dreader[46].ToString(); txtOtherPay.Text = dreader[47].ToString(); textBox1.Text = dreader[48].ToString(); button1.Text = dreader[49].ToString(); //txtname.Text = dreader[1].ToString(); //txtage.Text = dreader[2].ToString(); //txtcourse.Text = dreader[3].ToString(); ClearData(); } else { MessageBox.Show(" No Record"); } dreader.Close(); } catch (Exception x) { MessageBox.Show("No Record:\n" + x.Message); } finally { con.Close(); } } } private void btnDelete_Click(object sender, EventArgs e) { if (textBox1.Text == "") { MessageBox.Show("Please enter valid data..."); } else { FileStream fs = new FileStream(textBox1.Text, FileMode.OpenOrCreate, FileAccess.Read); byte[] bt = new byte[fs.Length]; fs.Read(bt, 0, System.Convert.ToInt32(fs.Length)); fs.Close(); // System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(); //cmd.CommandType = System.Data.CommandType.Text; //SqlDataAdapter adapt = new SqlDataAdapter(); SqlConnection con = new SqlConnection(); con.ConnectionString = "Data Source=AKINTOMIDE-HP\\SQLEXPRESS;Initial Catalog=fham;Integrated Security=True"; //SqlCommand cmd = new SqlCommand("delete master where txteid.Text =@eid", con); cmd = new SqlCommand("delete master where eid =@eid", con); con.Open(); cmd.Parameters.AddWithValue("@eid", txteid.Text); cmd.Parameters.AddWithValue("@yr", cmbYr.Text); cmd.Parameters.AddWithValue("@dat", datAd.Text); cmd.Parameters.AddWithValue("@datead", datEmp.Text); cmd.Parameters.AddWithValue("@datemod", DatMod.Text); cmd.Parameters.AddWithValue("@staf", txtStaf.Text); cmd.Parameters.AddWithValue("@adrs", txtAdrs.Text); cmd.Parameters.AddWithValue("@coy", txtCoy.Text); cmd.Parameters.AddWithValue("@dpt", cmbDpt.Text); cmd.Parameters.AddWithValue("@loc", cmbLoc.Text); cmd.Parameters.AddWithValue("@grd", CmbGrd.Text); cmd.Parameters.AddWithValue("@accno", TxtAccno.Text); cmd.Parameters.AddWithValue("@email", txtemail.Text); cmd.Parameters.AddWithValue("@picstaffpix", bt); cmd.Parameters.AddWithValue("@bank", cmbBank.Text); cmd.Parameters.AddWithValue("@penadmin", cmbPenAdmin.Text); cmd.Parameters.AddWithValue("@status", cmbStatus.Text); cmd.Parameters.AddWithValue("@pennum", txtPenNum.Text); cmd.Parameters.AddWithValue("@bsal", txtBSal.Text); cmd.Parameters.AddWithValue("@dres", txtDres.Text); cmd.Parameters.AddWithValue("@dupfront", txtDUpfront.Text); cmd.Parameters.AddWithValue("@educ", txtEduc.Text); cmd.Parameters.AddWithValue("@furn", txtFurn.Text); cmd.Parameters.AddWithValue("@harz", txtHarz.Text); cmd.Parameters.AddWithValue("@tran", txtTran.Text); cmd.Parameters.AddWithValue("@hous", txtHous.Text); cmd.Parameters.AddWithValue("@lunc", txtLunc.Text); cmd.Parameters.AddWithValue("@uti", txtUti.Text); cmd.Parameters.AddWithValue("@housM", txtHousM.Text); cmd.Parameters.AddWithValue("@risk", txtRisk.Text); cmd.Parameters.AddWithValue("@veh", txtVeh.Text); cmd.Parameters.AddWithValue("@pfs", txtPfS.Text); cmd.Parameters.AddWithValue("@nhf", txtNHF.Text); cmd.Parameters.AddWithValue("@nhfs", txtNHFS.Text); cmd.Parameters.AddWithValue("@oded", txtOded.Text); cmd.Parameters.AddWithValue("@pens", txtPens.Text); cmd.Parameters.AddWithValue("@paye", this.txtPAYE.Text); cmd.Parameters.AddWithValue("@tded", txtTDed.Text); cmd.Parameters.AddWithValue("@driv", txtDriv.Text); cmd.Parameters.AddWithValue("@dome", txtDome.Text); cmd.Parameters.AddWithValue("@tpay", txtTPay.Text); cmd.Parameters.AddWithValue("@npay", txtNPay.Text); cmd.Parameters.AddWithValue("@housU", this.txtHousU.Text); cmd.Parameters.AddWithValue("@staffM", this.txtStaffM.Text); cmd.Parameters.AddWithValue("@thrift", this.txtThrift.Text); cmd.Parameters.AddWithValue("@mon", cmbMon.Text); cmd.Parameters.AddWithValue("@otherP", this.txtOtherPay.Text); cmd.Parameters.AddWithValue("@photo", this.textBox1.Text); cmd.Parameters.AddWithValue("@BrowsePic", this.button1.Text); cmd.Connection = con; try { int k = cmd.ExecuteNonQuery(); MessageBox.Show("Deleted..."); textBox1.Text = ""; } catch (Exception ex) { MessageBox.Show("Not Deleted:\n" + ex.Message); } finally { con.Close(); } } } private void DisplayData() { } // Clear Data private void ClearData() { txteid.Text = "FHA136";//1 cmbYr.Text = ""; //DateTime.Now.ToShortDateString() datAd.Text = DateTime.Now.ToShortDateString(); //datAd.Text = DateTime.Now.ToShortDateString(); datEmp.Text = DateTime.Now.ToShortDateString(); DatMod.Text = DateTime.Now.ToShortDateString(); txtStaf.Text = "Akintomide Ayodele"; txtAdrs.Text = "39 Durban Street, Wuse II, Abuja"; txtCoy.Text = "FHA Homes Ltd"; cmbDpt.Text = "Operations"; cmbLoc.Text = "Abuja"; CmbGrd.Text = "Banking Officer"; TxtAccno.Text = "11234567"; txtemail.Text = "info@fhamortgage.gov.ng"; // picStafPix.Image=""; // bt // this.picStafPix.Image = new Bitmap(open.FileName); cmbBank.Text = "United Bank of Africa"; cmbPenAdmin.Text = "Crusader"; cmbStatus.Text = "staff"; txtPenNum.Text = "pen1234"; txtBSal.Text = "20000"; txtDres.Text = "0"; txtDUpfront.Text = "0"; txtEduc.Text = "0"; txtFurn.Text = "0"; txtHarz.Text = "0"; txtTran.Text = "0"; txtHous.Text = "30000"; txtLunc.Text = "0"; txtUti.Text = "0"; txtHousM.Text = "0"; txtRisk.Text = "0"; txtVeh.Text = "0"; txtPfS.Text = "0"; txtNHF.Text = "0"; txtNHFS.Text = "0"; txtOded.Text = "0"; txtPens.Text = "0"; txtPAYE.Text = "0"; txtTDed.Text = "0"; txtDriv.Text = "0"; txtDome.Text = "0"; txtTPay.Text = "0"; txtNPay.Text = "0"; txtHousU.Text = "0"; txtStaffM.Text = "0"; txtThrift.Text = "0"; cmbMon.Text = "October"; //txtOtherPay.Text = "0"; this.txtOtherPay.Text = "0"; // picStafPix.ImageLocation = textBox1.Text; textBox1.Text = ""; button1.Text = ""; SN = 0; } //New Record private void New_Rec() { } private void Add_Employee_Load(object sender, EventArgs e) { { if (con.State == ConnectionState.Closed) { con.Open(); } string sqlLoc = "SELECT * FROM Location"; var lAdapter = new SqlDataAdapter(sqlLoc, con); var lset = new DataSet(); lAdapter.TableMappings.Add("Table", "Location"); lAdapter.Fill(lset); this.dviewmanager = lset.DefaultViewManager; try { for (int i = 0; i <= lset.Tables[0].Rows.Count - 1; i++) { this.cmbLoc.Items.Add(lset.Tables[0].Rows[i]["Location"].ToString()); } } catch (Exception ex) { MessageBox.Show("Not successful:\n" + ex.Message); } this.cmbMon.Items.Add("January"); this.cmbMon.Items.Add("February"); this.cmbMon.Items.Add("March"); this.cmbMon.Items.Add("April"); this.cmbMon.Items.Add("May"); this.cmbMon.Items.Add("June"); this.cmbMon.Items.Add("July"); this.cmbMon.Items.Add("August"); this.cmbMon.Items.Add("September"); this.cmbMon.Items.Add("October"); this.cmbMon.Items.Add("November"); this.cmbMon.Items.Add("December"); } } protected void FillBank() { if (con.State == ConnectionState.Closed) { con.Open(); } string sqlStr = "SELECT * FROM BANK"; var dAdapter = new SqlDataAdapter(sqlStr, con); var dset = new DataSet(); dAdapter.TableMappings.Add("Table", "Bank"); dAdapter.Fill(dset); this.dviewmanager = dset.DefaultViewManager; try { for (int i = 0; i <= dset.Tables[0].Rows.Count - 1; i++) { this.cmbBank.Items.Add(dset.Tables[0].Rows[i]["Bank"].ToString()); } } catch (Exception ex) { //Exception Message MessageBox.Show("Not successful:\n" + ex.Message); } } protected void FillDpt() { if (con.State == ConnectionState.Closed) { con.Open(); } string sqlStr = "SELECT * FROM Dpt"; var dAdapter = new SqlDataAdapter(sqlStr, con); var dset = new DataSet(); dAdapter.TableMappings.Add("Table", "Dpt"); dAdapter.Fill(dset); this.dviewmanager = dset.DefaultViewManager; try { for (int i = 0; i <= dset.Tables[0].Rows.Count - 1; i++) { this.cmbDpt.Items.Add(dset.Tables[0].Rows[i]["Dpt"].ToString()); } } catch (Exception ex) { //Exception Message MessageBox.Show("Not successful:\n" + ex.Message); } } protected void FillYear() { if (con.State == ConnectionState.Closed) { con.Open(); } string sqlStr = "SELECT * FROM Year"; var dAdapter = new SqlDataAdapter(sqlStr, con); var dset = new DataSet(); dAdapter.TableMappings.Add("Table", "Year"); dAdapter.Fill(dset); this.dviewmanager = dset.DefaultViewManager; try { for (int i = 0; i <= dset.Tables[0].Rows.Count - 1; i++) { this.cmbYr.Items.Add(dset.Tables[0].Rows[i]["Year"].ToString()); } } catch (Exception ex) { //Exception Message MessageBox.Show("Not successful:\n" + ex.Message); } } protected void FillGrade() { if (con.State == ConnectionState.Closed) { con.Open(); } string sqlStr = "SELECT * FROM Grade"; var dAdapter = new SqlDataAdapter(sqlStr, con); var dset = new DataSet(); dAdapter.TableMappings.Add("Table", "Grade"); dAdapter.Fill(dset); this.dviewmanager = dset.DefaultViewManager; try { for (int i = 0; i <= dset.Tables[0].Rows.Count - 1; i++) { this.CmbGrd.Items.Add(dset.Tables[0].Rows[i]["Grade"].ToString()); } } catch (Exception ex) { //Exception Message MessageBox.Show("Not successful:\n" + ex.Message); } } protected void FillStatus() { if (con.State == ConnectionState.Closed) { con.Open(); } string sqlStr = "SELECT * FROM Status"; var dAdapter = new SqlDataAdapter(sqlStr, con); var dset = new DataSet(); dAdapter.TableMappings.Add("Table", "Status"); dAdapter.Fill(dset); this.dviewmanager = dset.DefaultViewManager; try { for (int i = 0; i <= dset.Tables[0].Rows.Count - 1; i++) { this.cmbStatus.Items.Add(dset.Tables[0].Rows[i]["Status"].ToString()); } } catch (Exception ex) { //Exception Message MessageBox.Show("Not successful:\n" + ex.Message); } } protected void FillPenAdmin() { if (con.State == ConnectionState.Closed) { con.Open(); } string sqlStr = "SELECT * FROM PenAdmin"; var dAdapter = new SqlDataAdapter(sqlStr, con); var dset = new DataSet(); dAdapter.TableMappings.Add("Table", "PenAdmin"); dAdapter.Fill(dset); this.dviewmanager = dset.DefaultViewManager; try { for (int i = 0; i <= dset.Tables[0].Rows.Count - 1; i++) { this.cmbPenAdmin.Items.Add(dset.Tables[0].Rows[i]["PenAdmin"].ToString()); } } catch (Exception ex) { //Exception Message } } private void groupBox1_Enter(object sender, EventArgs e) { } private void label14_Click(object sender, EventArgs e) { } private void frmTpay_Enter(object sender, EventArgs e) { } private void txtHousU_TextChanged(object sender, EventArgs e) { } private void label33_Click(object sender, EventArgs e) { } private void txtStaffM_TextChanged(object sender, EventArgs e) { } private void txtPAYE_TextChanged(object sender, EventArgs e) { } private void datEmp_ValueChanged(object sender, EventArgs e) { //// Set title bar to selected date. //DateTime result = dateTimePicker1.Value; //this.Text = result.ToString(); } private void btnClose_Click(object sender, EventArgs e) { this.Dispose(); } private void txtTran_TextChanged(object sender, EventArgs e) { } private void textBox1_TextChanged(object sender, EventArgs e) { //SaveImage(); } } }
Richard Deeming
Неужели вы всерьез ожидаете, что кто-то проберется через эту массивную стену кода, чтобы решить, где проблема?!
Отредактируйте вопрос, удалите любой ненужный код, добавьте полную информацию об исключении и сообщите нам, из какой строки кода оно было выброшено.
Если исключение относится к входным данным, то мы не можем вам помочь, потому что не видим, какие данные вы ввели. Вам нужно отладить свой код и найти проблему.