none
Database(SQL Server 2017) project in Visual basic 2017. RRS feed

  • Question

  • How to display data in text boxes in vb 2017.My code is:

    Imports System.Data
    Imports System.Data.SqlClient
    Class MainWindow
        Dim objConnection As New SqlConnection _
            ("Data Source=DESKTOP-5JD8FE5;Initial Catalog=Abhilekh;Integrated Security=True")
        Dim objDataAdapter As New SqlDataAdapter(
            "SELECT ID, Name, Age " &
                     "FROM a " &
                     "ORDER BY ID, Name, Age", objConnection)
        Dim objDataSet As DataSet
        Dim objDataView As DataView
        'Dim objCurrencyManager As CurrencyManager
        Private Sub FillDataSetAndView()
            ' Initialize a new instance of the DataSet object.
            objDataSet = New DataSet()
            ' Fill the DataSet object with data..
            objDataAdapter.Fill(objDataSet, "a")
            ' Set the DataView object to the DataSet object..
            objDataView = New DataView(objDataSet.Tables("a"))
            ' Set our CurrencyManager object to the DataView object..
            objCurrencyManager = CType(Me.BindingContext(objDataView), CurrencyManager)
        End Sub
        Private Sub BindFields()
            ' Clear any previous bindings..
            txtID.DataBindings.Clear()  ......................................................SHOWING ERROR AT THIS LEVEL.(Severity Code Description Project File Line Suppression State
    Error BC30456 'DataBindings' is not a member of 'TextBox'. new C:\Users\sheel\source\repos\new\new\MainWindow.xaml.vb 31 Active
    )
            txtName.DataBindings.Clear()
            txtAge.DataBindings.Clear()

            ' Add new bindings to the DataView object..
            txtID.DataBindings.Add("Text", objDataView, "ID")
            txtName.DataBindings.Add("Text", objDataView, "Name")
            txtAge.DataBindings.Add("Text", objDataView, "Age")
            ' Display a ready status..
            ToolStripStatusLabel1.Text = "Ready"
        End Sub
        Private Sub Form1_Load(sender As Object,
                   e As EventArgs) Handles MyBase.Loaded
            'TODO: This line of code loads data into the 'PatientDataSet.dept1' table. You can move, or remove it, as needed.
            ' Dept1TableAdapter.Fill(PatientDataSet.dept1)
            ' Label12.Text = Date.Now
            ' Add items to the combo box..
            'ComboBox1.Items.Add("Select Department")
            cbofield.Items.Add("Last Name")
            cbofield.Items.Add("First Name")
            cbofield.Items.Add("PatientID")
            ' Make the first item selected..
            cbofield.SelectedIndex = 0
            ' Fill the DataSet and bind the fields..
            FillDataSetAndView()
            ' BindFields()
            ' Show the current record position..
            ' ShowPosition()

        End Sub
        Private Sub button_Click(sender As Object, e As RoutedEventArgs) Handles button.Click
            End
        End Sub
    End Class
    Friday, January 19, 2018 5:59 AM

Answers

  • You use WPF while the code is for Windows Forms. 

    WPF has despite the they wrote on Internet it is better, afaik not such a fine databinding mechanism as windows forms. 

    I myself just set and get it in the classic way. 


    Success Cor

    • Marked as answer by sheelnath Saturday, January 27, 2018 3:26 PM
    Friday, January 19, 2018 7:50 AM
  • You do the binding in the XAML. The link below shows the basics and not a solution to your exact situation.

    https://www.codeproject.com/Articles/29054/WPF-Data-Binding-Part


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by sheelnath Saturday, January 27, 2018 3:26 PM
    Friday, January 19, 2018 10:23 AM
    Moderator

All replies

  • You use WPF while the code is for Windows Forms. 

    WPF has despite the they wrote on Internet it is better, afaik not such a fine databinding mechanism as windows forms. 

    I myself just set and get it in the classic way. 


    Success Cor

    • Marked as answer by sheelnath Saturday, January 27, 2018 3:26 PM
    Friday, January 19, 2018 7:50 AM
  • You do the binding in the XAML. The link below shows the basics and not a solution to your exact situation.

    https://www.codeproject.com/Articles/29054/WPF-Data-Binding-Part


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by sheelnath Saturday, January 27, 2018 3:26 PM
    Friday, January 19, 2018 10:23 AM
    Moderator