Saturday, March 24, 2012

Populate form fields

How do you populate individual form fields from a database? I have used datasets in the past but this time I need to do individual form fields.

Below is the code I tried and I know that reader only read 1 parameter and not the way I have it setup now to do multiple parameters.

thanks

1Dim sConnStrAs String = ConfigurationManager.ConnectionStrings("accmon").ConnectionString23'************************45Dim MySqlAs String ="SELECT * FROM privacyscan WHERE privacyscanDelete = 0 and url ='" & privacyAddress & "'"67 Dim reader As OleDb.OleDbDataReader89 Dim MyConn As New OleDbConnection(sConnStr)10 Dim Cmd As New OleDbCommand(MySql, MyConn)1112 MyConn.Open()13 reader = Cmd.ExecuteReader()1415 While reader.Read()16 txtOA.Text = reader("oa")17'txtDate.Text = reader("date")18 'txtURL.Text = reader("url")19 'txtReport.Text = reader("report")20 'txtScan11.Text = reader("chkpt_scan_11")21 'txtPass11.Text = reader("chkpt_pass_11")22 'txtScan14.Text = reader("chkpt_scan_14")23 'txtPass14.Text = reader("chkpt_pass_14")24 'txtScan15.Text = reader("chkpt_scan_15")25 'txtPass15.Text = reader("chkpt_pass_15")26 'txtScan22.Text = reader("chkpt_scan_22")27 'txtPass22.Text = reader("chkpt_pass_22")28 'txtScan31.Text = reader("chkpt_scan_31")29 'txtPass31.Text = reader("chkpt_pass_31")30 'txtScan32.Text = reader("chkpt_scan_32")31 'txtPass32.Text = reader("chkpt_pass_32")32 'txtScan41.Text = reader("chkpt_scan_41")33 'txtPass41.Text = reader("chkpt_pass_41")34 'txtScan41a.Text = reader("chkpt_scan_41a")35 'txtPass41a.Text = reader("chkpt_pass_41a")36 'txtScan41b.Text = reader("chkpt_scan_41b")37 'txtPass41b.Text = reader("chkpt_pass_41b")38 'txtScan42.Text = reader("chkpt_scan_42")39 'txtPass42.Text = reader("chkpt_pass_42")40 'txtScan43.Text = reader("chkpt_scan_43")41 'txtPass43.Text = reader("chkpt_pass_43")42 'txtScan44.Text = reader("chkpt_scan_44")43 'txtPass44.Text = reader("chkpt_pass_44")44 'txtScan71.Text = reader("chkpt_scan_71")45 'txtPass71.Text = reader("chkpt_pass_71")46End While47 reader.Close()48 MyConn.Close()

Well, if you uncomment the lines below then your code should be working fine. However, if your query returns more than one row, your controls will only show the last row returned (since you have a while loop).

Another thing you might want to check is the layout of your table. It doesn't seem very normalized ;-)


What is the problem with the current code? However everytime you need to make sure you are returning only one row.

0 comments:

Post a Comment