(http://s14.directupload.net/images/140127/fooispgt.jpg)图片链接
请查看图片以获得更多关于问题的说明bcz我知道我无法让您更清楚。
我想只更新那些由用户通过复选框检查的列的数据,而那些未经检查的列不会被NULL值更新....
我在想的是使用511 if .... else为不同的更新查询条件,但是不可能实现它。
到目前为止,更新代码是:
else if(update_rdbtn.Checked)
{
FileStream fstream = new FileStream(this.imglocation_lbl.Text, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fstream);
imgbtarray = br.ReadBytes((int)fstream.Length);
SqlConnection con = new SqlConnection("Data Source=JackSparrow-PC\\sqlexpress;Initial Catalog=HCE_DB;Integrated Security=True;Pooling=False");
SqlCommand cmd = new SqlCommand("Update StudentInfo SET Rollno='" + this.rollno_txtbox.Text + "',Student_Name='" + this.studname_txtbox.Text + "',F_name='" + this.fname_txtbox.Text + "',D_O_B='" + this.dob_txtbox.Text + "',Address='" + this.address_txtbox.Text + "',Phone='" + this.phone_txtbox.Text + "',Valid_upto='" + this.validupto_txtbox.Text + "',Image=@IMG,Branch='" + this.branch_txtbox.Text + "' WHERE Rollno='" + this.rollno_txtbox.Text + "';", con);
SqlDataReader myReader;
try
{
con.Open();
cmd.Parameters.Add(new SqlParameter("@IMG", imgbtarray));
myReader = cmd.ExecuteReader();
MessageBox.Show("Data has been updated");
myReader.Close();
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
已检查的电台btn代码已更改:
private void update_rdbtn_CheckedChanged(object sender, EventArgs e)
{
update_grpbox.Enabled = true;
studname_txtbox.Enabled = false;
fname_txtbox.Enabled = false;
dob_txtbox.Enabled = false;
branch_txtbox.Enabled = false;
address_txtbox.Enabled = false;
phone_txtbox.Enabled = false;
validupto_txtbox.Enabled = false;
Browse_btn.Enabled = false;
studname_chkbox.Checked = false;
fname_chkbox.Checked = false;
dob_chkbox.Checked = false;
branch_chkbox.Checked = false;
Address_chkbox.Checked = false;
phone_chkbox.Checked = false;
validupto_chkbox.Checked = false;
Uploadimg_chkbox.Checked = false;
}
复选框代码:
private void studname_chkbox_CheckedChanged(object sender, EventArgs e)
{
if (!studname_chkbox.Checked)
{
studname_txtbox.Enabled = false;
}
else
{
studname_txtbox.Enabled = true;
}
}
private void fname_chkbox_CheckedChanged(object sender, EventArgs e)
{
if (!fname_chkbox.Checked)
{
fname_txtbox.Enabled = false;
}
else
{
fname_txtbox.Enabled = true;
}
}
private void dob_chkbox_CheckedChanged(object sender, EventArgs e)
{
if (!dob_chkbox.Checked)
{
dob_txtbox.Enabled = false;
}
else
{
dob_txtbox.Enabled = true;
}
}
private void branch_chkbox_CheckedChanged(object sender, EventArgs e)
{
if (!branch_chkbox.Checked)
{
branch_txtbox.Enabled = false;
}
else
{
branch_txtbox.Enabled = true;
}
}
private void Address_chkbox_CheckedChanged(object sender, EventArgs e)
{
if (!Address_chkbox.Checked)
{
address_txtbox.Enabled = false;
}
else
{
address_txtbox.Enabled = true;
}
}
private void phone_chkbox_CheckedChanged(object sender, EventArgs e)
{
if (!phone_chkbox.Checked)
{
phone_txtbox.Enabled = false;
}
else
{
phone_txtbox.Enabled = true;
}
}
private void validupto_chkbox_CheckedChanged(object sender, EventArgs e)
{
if (!validupto_chkbox.Checked)
{
validupto_txtbox.Enabled = false;
}
else
{
validupto_txtbox.Enabled = true;
}
}
private void Uploadimg_chkbox_CheckedChanged(object sender, EventArgs e)
{
if (!Uploadimg_chkbox.Checked)
{
Browse_btn.Enabled = false;
}
else
{
Browse_btn.Enabled = true;
}
}