Invalid Column Name issue
<p><br>
I am working in vb.net and facing an Issue of invalid column name when accessing the data from SQL.<br>
I am using MSSQL as back-end.</p>

<p>I referred many links, googled alot but unable to solve my problem</p>

<p>The code where I am facing problem is : </p>

<pre><code>Private Sub txtAccCode_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtAccCode.TextChanged
    Try
           mQry = " from FAMPAR where Account_Code = '" &amp; txtAccCode.Text &amp; "'"
        If Not CheckEof("select *" &amp; mQry, con1) Then
            txtAccName.Text = GetData("select Party_Name " &amp; mQry, con1)
            txtProPart.Text = GetData("select Proprietor" &amp; mQry, con1)
            txtRef.Text = GetData("select Reference_By" &amp; mQry, con1)
            txtAdd1.Text = GetData("select Address_1" &amp; mQry, con1)
            txtAdd2.Text = GetData("select Address_2" &amp; mQry, con1)
            txtCity.Text = GetData("select City" &amp; mQry, con1)
            txtPhno.Text = GetData("select Phone_No" &amp; mQry, con1)
            txtEmail.Text = GetData("select Email" &amp; mQry, con1)
            txtDrugLic.Text = GetData("select Drug_License" &amp; mQry, con1)
            txtGst.Text = GetData("select GST_No" &amp; mQry, con1)
            txtCst.Text = GetData("select CST_No" &amp; mQry, con1)
            txtCustBank.Text = GetData("select Customer_Bank" &amp; mQry, con1)
            txtAreaCode.Text = GetData("select Area_Code" &amp; mQry, con1)
            txtCustGrpCode.Text = GetData("select Cust_GrpCode" &amp; mQry, con1)
            txtDisc.Text = GetData("select Disc_Perc" &amp; mQry, con1)
            txtOpeningBal.Text = GetData("select Open_Bal" &amp; mQry, con1)
            txtCurrBal.Text = GetData("select Curr_Bal" &amp; mQry, con1)
            txtCcd.Text = GetData("select CC_DD" &amp; mQry, con1)
            txtStopDays.Text = GetData("select Stop_Days" &amp; mQry, con1)
            txtBillOutstdg.Text = GetData("select Fix_Days" &amp; mQry, con1)
            txtRemarks.Text = GetData("select Description" &amp; mQry, con1)
            cmbRetTax.Text = GetData("select Retail_Taxable" &amp; mQry, con1)
        End If
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
End Sub
</code></pre>

<p>The GetData function I used in above code is </p>

<pre><code>Function GetData(qry As String, Xcn As SqlConnection)
    Try
        da = New SqlDataAdapter(qry, Xcn)
        dt = New DataTable
        da.Fill(dt)
        GetData = IIf(Trim(dt.Rows(0).Item(0)) &lt;&gt; "", Trim(dt.Rows(0).Item(0)), "")
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
End Function
</code></pre>

<p>Now the problem is it works correct till textAreaCode.text but after than from textCustGrpCode.text error starts saying "invalid Column name (name of column)". The error screen-shot is shown in the link below..</p>

<p><a href="http://i.stack.imgur.com/fq5z6.png" rel="nofollow">Error Image-Click here</a></p>

<p>The other thing is when I twist txtAreaCode.text line position with txtCustGrpCode.text line or any other below it, textAreaCode.text gives the error as "Invalid Column Name(column Name)" and the other line works properly.</p>

<p>Plz tell me where I did mistake...<br>
Any help will be accepted..!</p>