I posted a question earlier but it is so complicated that I think that's the reason why nobody tries to answer it. So I decided to put this in the simplest way I can. So here is my code:
Private Sub frmcrc_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
conn = GetConnect()
Dim com As New SqlClient.SqlCommand
Dim dr As SqlClient.SqlDataReader
conn.Open()
com.CommandText = "Select * from tblCRClearance where crc_no = '" & frmComm.txtCRCNum1.Text & "'"
com.Connection = conn
dr = com.ExecuteReader
dr.Read()
txtCRCNo.Text = dr!crc_no
txtCLTAcctNo.Text = dr!crc_clientno
lblrootpayee.Text = dr!crc_rootpayee
txtPayeeName.Text = dr!crc_payeename
txtClientName.Text = dr!crc_clientname
txtProjName.Text = dr!crc_projectname
txtCommType.Text = dr!crc_commtype
txtGrossAmt.Text = dr!crc_grossamount
txtWTax.Text = dr!crc_withheld
txtCALType1.Text = dr!crc_caliqtype1
txtCALDate1.Text = dr!crc_caliqdate1
txtCALNo1.Text = dr!crc_caliqnum1
txtCALAmt1.Text = dr!crc_caliqamt1
txtCALDesc1.Text = dr!crc_caliqdesc1
txtCALType2.Text = dr!crc_caliqtype2
txtCALNo2.Text = dr!crc_caliqnum2
txtCALAmt2.Text = dr!crc_caliqnum2
txtCALDate2.Text = dr!crc_caliqdate2
txtCALDesc2.Text = dr!crc_caliqdesc2
txtCALType3.Text = dr!crc_caliqtype3
txtCALDate3.Text = dr!crc_caliqdate3
txtCALNo3.Text = dr!crc_caliqnum3
txtCALAmt3.Text = dr!crc_caliqamt3
txtCALDesc3.Text = dr!crc_caliqdesc3
txtCALIQ.Text = dr!crc_caliqtotal
txtNetAmt.Text = dr!crc_netamount
txtVoucherNum.Text = dr!crc_voucherno
txtCRLNum.Text = dr!crc_crlno
txtDate.Text = dr!crc_date
txtCPFNo.Text = dr!crc_cpfno
txtPreparedBy.Text = dr!crc_preparedby
txtCheckedBy.Text = dr!crc_checkedby
txtApprovedBy.Text = dr!crc_approvedby
txtGrossPrice.Text = dr!crc_grossprice
txtLess1.Text = dr!crc_lessprice1
txtDesc1.Text = dr!crc_lessdesc1
txtLess2.Text = dr!crc_lessprice2
txtDesc2.Text = dr!crc_lessdesc2
txtLess3.Text = dr!crc_lessprice3
txtDesc3.Text = dr!crc_lessdesc3
txtNetSellingP.Text = dr!crc_netsellingprice
txtRate.Text = dr!crc_rate
txtGrossRel.Text = dr!crc_grossrelease
txtDed1.Text = dr!crc_ded1
txtDDesc1.Text = dr!crc_deddesc1
txtDed2.Text = dr!crc_ded2
txtDDesc2.Text = dr!crc_deddesc2
txtDed3.Text = dr!crc_ded3
txtDDesc3.Text = dr!crc_deddesc3
txtDed4.Text = dr!crc_ded4
txtDDesc4.Text = dr!crc_deddesc4
txtDed5.Text = dr!crc_ded5
txtNetRel.Text = dr!crc_netrelease
txtCollectibles.Text = dr!crc_collectibles
conn.Close()
txtCLTAcctNo.Text = frmComm.cmbAcctNo1.Text
txtCRLNum.Text = frmComm.txtCRLNo.Text
txtProjName.Text = frmComm.txtUnitCode1.Text
txtClientName.Text = frmComm.cmbClientName1.Text + " " + frmComm.Label13.Text
txtCommType.Text = frmComm.cmbParticulars1.Text
txtPayeeName.Text = frmComm.cmbPayee01.Text
Me.lblrootpayee.Text = frmComm.lblrootpayee.Text
End Sub
It works like this: the sql query gets the data with the crc number the same as in txtCRCNum1. It works just as how I want it to, but I have some issues about this. I have 30 textboxes just like txtCRCNum1, so there are going to be 30 different values of crc number, depending on which textbox will I get its value. I want to have a conditional statement wherein it checks if the textbox that should contain the crc number is empty. If it is empty, then the fields will display just do this:
txtCLTAcctNo.Text = frmComm.cmbAcctNo1.Text
txtCRLNum.Text = frmComm.txtCRLNo.Text
txtProjName.Text = frmComm.txtUnitCode1.Text
txtClientName.Text = frmComm.cmbClientName1.Text + " " + frmComm.Label13.Text
txtCommType.Text = frmComm.cmbParticulars1.Text
txtPayeeName.Text = frmComm.cmbPayee01.Text
Me.lblrootpayee.Text = frmComm.lblrootpayee.Text
If not empty, then it will execute the sql query part.
How should I put up the conditional statement so that it will work as I have described?
"Where crc_no = " & myCrcVal.ToString. This form would use variable value and not need to use an IF except maybe if the var is String.Empty. Even that could be minimized. And do use parameters for queries.If txtCRCNum1.Text <> "" Then 'sql query else 'display some values