0

在我的 Windows 窗体中,我有一个Button名为 Save。当我单击该按钮时,如果表单中的所有字段均已成功验证,则应将数据保存到数据库中。否则,应显示错误消息。

我努力了:

private void btnNotesSave_Click(object sender, EventArgs e)
{
    if (this.ValidateChildren(ValidationConstraints.None))
    {
        DataRow dr = ds.Tables[0].NewRow();
        dr[0] = txtName.Text;
        dr[1] = txtPersonResponsible.Text;
        dr[2] = txtPersonResponsibleIDDetails.Text;
        dr[3] = txtAlternativePersonResponsible.Text;
        dr[4] = txtAlternativePersonResponsibleIDDetails.Text;
        dr[5] = txtCompanyRegNo.Text;
        dr[6] = txtVatNo.Text;
        dr[7] = txtPremiseNo.Text;
        dr[8] = txtStreetName1.Text;
        dr[9] = txtStreetName2.Text;
        dr[10] = txtSubUrb.Text;
        dr[11] = txtCity.Text;
        dr[12] = txtProvince.Text;
        dr[13] = txtCountry.Text;
        dr[14] = txtPinCode.Text;
        dr[15] = txtPostalPremiseNo.Text;
        dr[16] = txtPostalStreetName1.Text;
        dr[17] = txtPostalStreetName2.Text;
        dr[18] = txtPostalSubUrb.Text;
        dr[19] = txtPostalCity.Text;
        dr[20] = txtPostalProvince.Text;
        dr[21] = txtPostalCountry.Text;
        dr[22] = txtPostalPinCode.Text;
        dr[23] = txtTelephone1.Text;
        dr[24] = txtTelephone2.Text;
        dr[25] = txtMobile1.Text;
        dr[26] = txtMobile2.Text;
        dr[27] = txtFax1.Text;
        dr[28] = txtFax2.Text;
        dr[29] = txtEmail1.Text;
        dr[30] = txtEmail2.Text;
        dr[31] = txtWebsite.Text;
        dr[32] = txtWorkingHours.Text;
        dr[33] = txtAccountHolderName.Text;
        dr[34] = txtBankName.Text;
        dr[35] = txtAccountType.Text;
        dr[36] = txtAccountNumber.Text;
        dr[37] = txtBranchCode.Text;
        dr[38] = rtxtBanking.Text;
        dr[39] = txtCreditLimit.Text;
        dr[40] = txtStartingDate.Text;
        dr[41] = txtEndingDate.Text;
        dr[42] = lstFinance.Text;
        dr[43] = rtxtFinance.Text;
        dr[44] = rtxtNotes.Text;
        ds.Tables[0].Rows.Add(dr);
        cb = new SqlCommandBuilder(da);
        da.Update(ds, "CompanyDetails");
        MessageBox.Show("data saved to DB");
    }
    else
        MessageBox.Show("please fill all mandatory fields");
}

但这不起作用。

提前致谢!!!

4

0 回答 0