Results 1 to 7 of 7

Thread: [RESOLVED] How show data into textBox SqlCE

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2012
    Posts
    47

    Resolved [RESOLVED] How show data into textBox SqlCE

    Hi,
    I'm trying to do a little program like an address book on a little device with windows mobile 6
    When I open the program I could:
    -Create a new DB and i new Table
    Code:
       Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            If TextBox1.Text = "" Then
                MsgBox("Inserire nome Agenda", MsgBoxStyle.OkOnly)
            Else
                NomeDB = TextBox1.Text
                MsgBox("\My Documents\" & NomeDb & ".sdf")
                System.IO.File.Delete("\My Documents\" & NomeDb & ".sdf")
                Dim SQLEngine As New SqlCeEngine("data source=\My Documents\" & NomeDb & ".sdf")
                SQLEngine.CreateDatabase()
                NomeDb = TextBox1.Text
    
                ' mi connetto al db
                conDati = New SqlCeConnection("Data Source=\My Documents\" & NomeDB & ".sdf")
                conDati.Open()
                'Creazione di un tabella
                SQL = "CREATE TABLE MiaTabella (ID int IDENTITY Primary Key " + "NOT NULL,Nome nvarchar(50) NOT NULL" + ",Cognome nvarchar(50) NOT NULL" + ",Telefono nvarchar(10) NOT NULL" + ",Mail nvarchar(30) NOT NULL)"
                CmdDati = New SqlCeCommand(SQL, conDati)
                CmdDati.CommandType = CommandType.Text
                CmdDati.ExecuteNonQuery()
                SQL = ""
                Me.Close()
                Form1.Show()
            End If
    or

    -Open a DB that already exist
    Code:
      Try
                conDati = New SqlCeConnection("Data Source=\My Documents\" & TextBox1.Text & ".sdf")
                conDati.Open()
                Me.Hide()
                Form1.Show()
            Catch Ex As Exception
                MsgBox(" Database non presente !!! Inserire nuovamente il nome del Database o crearne uno nuovo", MsgBoxStyle.OkOnly, "Attenzione")
            End Try
    I also insert address with this code
    Code:
     If ((TxtIN.Text = "") Or (TxtIC.Text = "")) Then
                MsgBox(" Inserire nome e cognome", MsgBoxStyle.OkOnly)
            Else
                SQL = "INSERT INTO MiaTabella (Nome,Cognome,Telefono,Mail) VALUES " + "('" & TxtIN.Text & "','" & TxtIC.Text & "','" & TxtIT.Text & "','" & TxtIE.Text & "')"
                MsgBox(SQL)
                CmdDati.CommandText = SQL
                CmdDati.ExecuteNonQuery()
                Pulisci()
            End If
    Now I have problem with : How show data in the Db into Textbox
    I don't understand how use Binding Source in the right way
    ,I would use the Binding source because i want to move next, previous....
    I try this code
    Code:
    Public Class Visualizza
        Dim Bs As BindingSource
        Dim Ds As Data.DataSet
        Dim Da As New SqlCeDataAdapter("SELECT * From MiaTabella", conDati)
        Dim table As New DataTable
        Dim Bs1 As BindingSource
    
        Public Sub Visualizza_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            
            Me.Da.Fill(table)
            Bs = New BindingSource(Da, "MiaTabella")  :(
            Mostra_Dati()
        End Sub
        Private Sub Mostra_Dati()
            TxtIN.Text = DirectCast(Bs.Current, DataRowView).Item("Nome").ToString
            TxtIC.Text = DirectCast(Bs.Current, DataRowView).Item("Cognome").ToString
            TxtIT.Text = DirectCast(Bs.Current, DataRowView).Item("Telefono").ToString
            TxtIE.Text = DirectCast(Bs.Current, DataRowView).Item("Mail").ToString
        End Sub
    But the program give me errors where there is the sad smile ,
    the errors is:
    Impossible to find the DataMember "MiaTabella" property into DataSource

    maybe I use the wrong method?? Maybe I have to use DataSet adn another Object?? Please Help Me
    I use Visual Studio 2008 for this project
    Thanks

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: How show data into textBox SqlCE

    The whole point of a BindingSource is to facilitate binding, so bind.
    vb.net Code:
    1. myBindingSource.DataSource = myDataTable
    2. myTextBox.DataBindings.Add("ControlPropertyName", myBindingSource, "DataSourceColumnOrPropertyName")

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2012
    Posts
    47

    Re: How show data into textBox SqlCE

    Ok, thank you I resolved my problem,but I would like to Know ,If it isn' a problem, how can i know if in an "x" directory there si an "y" DB?

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: How show data into textBox SqlCE

    The File.Exists method will tell you whether a file exists.

  5. #5

    Thread Starter
    Member
    Join Date
    Mar 2012
    Posts
    47

    Re: How show data into textBox SqlCE

    Ok perfect you are very useful

    If there isn't any problem i would like to do another question
    this is the code to delete a record
    Code:
     
    Chiave = DirectCast(Bs.Current, DataRowView).Item("ID")
            MsgBox(Chiave)
            MsgBox("Sei sicuro di voler eliminare questo contatto? ", MsgBoxStyle.YesNo, "Attenzione!")
            If vbYes Then
                If Not Conn.State = ConnectionState.Open Then Conn.Open()
                sqL = "DELETE * FROM MiaTabella WHERE ID= " & Chiave
                Cmd = New SqlCeCommand(sqL, Conn)
                Cmd.ExecuteNonQuery()
                Da.Update(Ds, "MiaTabella")
                Ds.Reset()
                Da.Fill(Ds, "Socio")
                Bs = New BindingSource(Ds, "Socio")
                DatiDB()
            End If
    but this code that work on an other program (but in vb 10 and with Access)
    doesn't work On Cmd.ExcuteNonQuery() give me this error
    Mistake during parsing the query. [ Token line number = 1,Token line offset = 8,Token in error = * ]

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: How show data into textBox SqlCE

    Please keep each thread to a single topic and each topic to a single thread. If you have a new question on a new topic, please create a new thread.

  7. #7

    Thread Starter
    Member
    Join Date
    Mar 2012
    Posts
    47

    Re: How show data into textBox SqlCE

    Ok sorry thank you for your answer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width