-
Apr 4th, 2012, 04:56 PM
#1
Thread Starter
Member
[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
-
Apr 4th, 2012, 11:03 PM
#2
Re: How show data into textBox SqlCE
The whole point of a BindingSource is to facilitate binding, so bind.
vb.net Code:
myBindingSource.DataSource = myDataTable myTextBox.DataBindings.Add("ControlPropertyName", myBindingSource, "DataSourceColumnOrPropertyName")
-
Apr 8th, 2012, 03:05 PM
#3
Thread Starter
Member
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?
-
Apr 8th, 2012, 09:11 PM
#4
Re: How show data into textBox SqlCE
The File.Exists method will tell you whether a file exists.
-
Apr 9th, 2012, 03:38 AM
#5
Thread Starter
Member
Re: How show data into textBox SqlCE
-
Apr 9th, 2012, 04:17 AM
#6
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.
-
Apr 9th, 2012, 11:18 AM
#7
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|