Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating Control Arrays in Vb 2010 with table column names not reading Rows
    primarykey
    data
    text
    <p>I am having problems with <strong>Creating Control Arrays</strong> and <strong>getting the Column Names for a table</strong>, I know that <strong>my string works</strong> as I have used the outputted string straight as a SQL query, the <strong>problem</strong> lies where it seems <strong>not</strong> to <strong>find any of the rows</strong> in the table(that i know are their, using the <strong>If lrd.HasRows</strong> Then I have seen that it does not find any rows <strong>(lrd.HasRows = False)</strong>. Is their a diffent <strong>Connection string</strong> for <strong>INFORMATION_SCHEMA.COLUMNS</strong> ?</p> <p>'Finds the Column Name</p> <pre><code>Public Sub findSQLColumnName(ByRef i As Integer, ByRef OutputValue As String, ByVal tableName As String) Dim con As New SqlConnection Dim cmd As New SqlCommand Dim lrd As SqlDataReader Dim TableNameParm As New SqlParameter("Tablename", tableName) 'adds in the new paramenter UserName TableNameParm.Direction = ParameterDirection.Output Dim LocationParm As New SqlParameter("Location", i) 'adds in the new paramenter UserName LocationParm.Direction = ParameterDirection.Input Call FindConnectionString(con) ' finds connection string cmd.Parameters.Add(TableNameParm) cmd.Parameters.Add(LocationParm) Call SQLSELECT_WHERE("INFORMATION_SCHEMA.COLUMNS", "COLUMN_NAME AS Output, ORDINAL_POSITION", True, " (TABLE_NAME = @Tablename) AND (ORDINAL_POSITION = @Location)", con, cmd, lrd) Try ' While lrd.Read() ' code writen within here for what is to be done with selected data. 'Call findSQLColumnValue("Output", lrd, OutputValue) 'End While If lrd.HasRows Then lrd.Read() Call findSQLColumnValue("Output", lrd, OutputValue) lrd.Close() 'Close connection before Redirecting. Else lrd.Close() End If ' Catch ex As Exception Finally con.Close() End Try End Sub </code></pre> <p>'Finds the value of a Column</p> <pre><code>Public Sub findSQLColumnValue(ByRef ColumnName As String, loader As SqlDataReader, ByRef OutputValue As String) OutputValue = (Convert.ToString(loader(ColumnName))).Trim End Sub </code></pre> <p>'Button Click (Creates the control array)</p> <pre><code>Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click Dim SQLCode As New SQLCode Dim TableLength As Integer Dim lblText(100) As String Call SQLCode.SQLFindNoColumns("PatientClinicalinformation", TableLength, lblTitlePatient, lblText) For i As Int16 = 1 To TableLength ' Create the label control and set its text attribute Dim Label2 As New Label Call SQLCode.findSQLColumnName(i.ToString, lblText(i), "PatientClinicalinformation") Label2.Text = lblText(i) Dim Literal2 As New Literal Literal2.Text = "&lt;br /&gt;" ' Add the control to the placeholder PlaceHolder1.Controls.Add(Label2) Label2.ID = "lbl" &amp; i PlaceHolder1.Controls.Add(Literal2) Next End Sub </code></pre> <p>'SelectWhere</p> <pre><code> Public Sub SQLSELECT_WHERE(ByVal Tables As String, ByVal Columns As String, ByVal WHERE As Boolean, ByVal WHEREStatement As String, ByRef connection As SqlConnection, ByRef command As SqlCommand, ByRef loader As SqlDataReader) connection.Open() command.Connection = connection If WHERE = False Then command.CommandText = " SELECT " &amp; Columns &amp; " FROM " &amp; Tables End If If WHERE = True Then command.CommandText = " SELECT " &amp; Columns &amp; " FROM " &amp; Tables &amp; " WHERE " &amp; WHEREStatement End If command.CommandText = command.CommandText loader = command.ExecuteReader() End Sub </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload