Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Having trouble databinding a textbox to display results from a search
 

Having trouble databinding a textbox to display results from a search

What I am trying to do is the following: The user enters a id number on a form and on the same form is a number of read-only text boxes which displays data associated with that ID number. I created the following code and ran it.

Imports System
Imports System.Data
Imports System.Data.SqlClient

Public Class Form1
    Dim ls_value As String = txtClaimNum.Text
    Dim myDataReader As SqlDataReader
    Dim myAdapter As SqlDataAdapter
    Dim myDataSet As DataSet
    Dim ClaimsDS As DataSet
    Dim ClaimsDV As DataView
   

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        'Dim ls_sql As String
        'ClaimsDS = New DataSet
        Dim conn As SqlConnection = New SqlConnection("Data Source=xxxxT;Initial Catalog=xxxx;Persist Security Info=xxxxUser ID=xxxxxxxx")
        Dim myCommand As SqlCommand = New SqlCommand("select * from Claims where ID ='" & txtClaimNum.Text & "'")

        If ls_value <> " " Then
            Try
                conn.Open()
                myAdapter = New SqlDataAdapter(myCommand)
                myAdapter.Fill(ClaimsDS, "vw_Claims_Search")
                Me.txtInsuredName.DataBindings.Add("Text", ClaimsDS, "INSUREDNAME")
                Me.txtClaimant.DataBindings.Add("Text", ClaimsDS, "CLAIMANT")
                Me.txtDateofLoss.DataBindings.Add("Text", ClaimsDS, "LOSSDATE")
                Me.txtDateReported.DataBindings.Add("Text", ClaimsDS, "CLAIMMADEDATE")
                MsgBox("Connection opened")
            Catch ex As Exception
                MsgBox("Error: " & ex.ToString)
            End Try
            ' conn.Close()
            'MsgBox("Connection closed")
        End If

    End Sub
End Class


This is the following erro I get:

System.InvalidOperationException was unhandled
Message="An error occurred creating the form. See Exception.InnerException for details. The error is: Object reference not set
Some programmer  Tuesday, June 09, 2009 3:10 PM

These are your designer generated files. Do you know how to find them at look at them?

If so, check out joke_app.My.MyApplication.Main line 81

and

joke_app.My.MyProject.MyForms line 190


www.insteptech.com
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
DeborahK  Thursday, June 11, 2009 8:38 PM
It looks like the bottom of your message was cut off (for me anyway). Which line is generating the error?
www.insteptech.com
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
DeborahK  Tuesday, June 09, 2009 6:29 PM
Sorry but this board is behaving a bit erratic for me today. But here is the stack trace of the error message. System.InvalidOperationException was unhandled
Message="An error occurred creating the form. See Exception.InnerException for details. The error is: Object reference not set to an instance of an object."
Source="joke_app"
StackTrace:
at joke_app.My.MyProject.MyForms.Create__Instance__[T](T Instance) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 190
at joke_app.My.MyProject.MyForms.get_Form1()
at joke_app.My.MyApplication.OnCreateMainForm() in C:\xxxx\My Project\Application.Designer.vb:line 35
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at joke_app.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Some programmer  Tuesday, June 09, 2009 7:19 PM
Does anyone else have any suggestions? Thanks in advance.
Some programmer  Thursday, June 11, 2009 8:15 PM

These are your designer generated files. Do you know how to find them at look at them?

If so, check out joke_app.My.MyApplication.Main line 81

and

joke_app.My.MyProject.MyForms line 190


www.insteptech.com
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
DeborahK  Thursday, June 11, 2009 8:38 PM
I would like this thread to be closed. I found out the error to be the following:

Dim sql As String = "select ....'" + txtClaimNum.Text + "'"

Dim conn As SqlConnection = New SqlConnection(connString)

Dim cmd As SqlCommand = New SqlCommand(sql, conn)

Try

conn.Open()

Dim rdr As SqlDataReader = cmd.ExecuteReader

While rdr.Read

txtInsuredName.Text = rdr(0).ToString

txtClaimant.Text = rdr(1).ToString

txtDateReported.Text = rdr(2).ToString

txtDateofLoss.Text = rdr(3).ToString

End While

Catch ex As Exception

MsgBox(

"Error: " & ex.ToString)

End Try

conn.Close()

End If

Some programmer  Wednesday, June 17, 2009 8:38 PM

You can use google to search for other answers

Custom Search

More Threads

• DataGridView Not Saving new Items, but updating existing ones
• DataGrid Column Color (FAQ 5.60) Question
• crystal Report command problem
• Datagridview Rows??
• how to do restrict char in datagridviewcell?
• Combo Boxes Bound To Objects Only Sometimes Update
• Programmatic Sorting with "custom business objects" in master/detail?
• datagrid odbc
• Update Datagridview with Multithreading
• cannot reuse an existing typed dataset in presentation project without having to use WCF