using (SqlConnection con = connection.getconnection()){
SqlCommand cmd = new SqlCommand("empreg", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@empid", txtempid.Text);
cmd.Parameters.AddWithValue("@empname", txtempname.Text);
cmd.Parameters.AddWithValue("@salary", txtsalary.Text);
cmd.Parameters.AddWithValue("@tell", txttell.Text);
cmd.Parameters.AddWithValue("@address", txtaddress.Text);
cmd.Parameters.AddWithValue("@blog", txtblog.Text);
cmd.Parameters.AddWithValue("@gender", cmbgender.Text);
cmd.Parameters.AddWithValue("@hiredate", dtpdate.Value);
cmd.Parameters.AddWithValue("@op", op);
int i = cmd.ExecuteNonQuery();
//If i > 0 AND op = "insert"
if (i > 0 && op == "insert"){
MessageBox.Show("1 row is saved sucessfuly ");
submode.readdgv("emp", DGV2);
submode.autoid(txtempid, "emp");
txtempname.Clear();
txtsalary.Clear();
txttell.Clear();
txtaddress.Clear();
txtblog.Clear();
cmbgender.SelectedIndex = -1;
dtpdate.Value = DateTime.Now;
txtempname.Focus();
}
else if (i >= 0 && op == "update"){
MessageBox.Show("1 row is updated sucessfuly ");
submode.readdgv("emp", DGV2);
submode.autoid(txtempid, "emp");
}
else if (i >= 0 && op == "delete"){
MessageBox.Show("1 row is deleted sucessfuly");
submode.readdgv("emp", DGV2);
submode.autoid(txtempid, "emp");
}
else{
MessageBox.Show("process is failed");
submode.readdgv("emp", DGV2);
submode.autoid(txtempid, "emp");
}
}
可悲的是,我對框架的瞭解並不適合編寫一個庫。感謝您帶領我走向正確的方向! – perotom
@perotom:好的,別擔心。也許,將來會找到這個問題的其他人可以這樣做:) –