I dont know how to link my table to the database yet i already finished connecting to the application itself.
i have four fields on the form as well in the database table. that is
1.word
2.lug_trans
3.Eng_trans
4.meaning
the same fields appear in the database tables.
i have to fill and hen after extract the data and display it on another form in four labels
i wish someone could help me

Dani AI

Generated

— good that asked to see code. Two common problems in cases like yours are (1) building SQL by concatenating control text (it both breaks easily and is insecure) and (2) using a raw file path rather than a proper connection string and the correct provider. Use parameterized commands, wrap connections/commands in Using so they are disposed, and keep the DB file in a known location (or use |DataDirectory|) so the runtime can find it.

Example: safe insert pattern (replace table/column names and control names to match your form)

Imports System.Data.SqlServerCe

Using cn As New SqlCeConnection("Data Source=|DataDirectory|\MyDatabase.sdf;")
    cn.Open()
    Using cmd As New SqlCeCommand("INSERT INTO YourTable (ColA, ColB, ColC, ColD) VALUES (@a,@b,@c,@d)", cn)
        cmd.Parameters.AddWithValue("@a", txtA.Text.Trim())
        cmd.Parameters.AddWithValue("@b", txtB.Text.Trim())
        cmd.Parameters.AddWithValue("@c", txtC.Text.Trim())
        cmd.Parameters.AddWithValue("@d", txtD.Text.Trim())
        cmd.ExecuteNonQuery()
    End Using
End Using

Example: read a single row and populate labels (check for DBNull before assigning)

Using cn As New SqlCeConnection("Data Source=|DataDirectory|\MyDatabase.sdf;")
    cn.Open()
    Using cmd As New SqlCeCommand("SELECT ColA, ColB, ColC, ColD FROM YourTable WHERE Id = @id", cn)
        cmd.Parameters.AddWithValue("@id", someId)
        Using rdr As SqlCeDataReader = cmd.ExecuteReader()
            If rdr.Read() Then
                lblA.Text = If(rdr.IsDBNull(0), String.Empty, rdr.GetString(0))
                lblB.Text = If(rdr.IsDBNull(1), String.Empty, rdr.GetString(1))
                lblC.Text = If(rdr.IsDBNull(2), String.Empty, rdr.GetString(2))
                lblD.Text = If(rdr.IsDBNull(3), String.Empty, rdr.GetString(3))
            End If
        End Using
    End Using
End Using

Quick tips: add a reference to System.Data.SqlServerCe, set the DB file’s Copy to Output Directory carefully (Copy if newer or leave it out if you want persistent data), and avoid AddWithValue pitfalls by specifying types when needed. For provider docs and Using patterns see the official references: and VB Using statement. If starting a new project, consider LocalDB/SQL Express or SQLite instead of older SQL CE.

Recommended Answers

All 2 Replies

lets see your code that you have so far.

ok the code i have generated sofar is hee

Dim cconnection As String = "C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\LugWdLib\LugWdLib\Database1.sdf"

Dim ebigambo As String = ekigambo.ToString() & "-" & lug_meaning.ToString() & "-" & word.ToString() & "-" & eng_meaning.ToString()
Dim sqlStr As String = "insert into word_name(ekigambo,lug_meaning,eng_meaning,word)values('" & ekigambo.Text.ToString & " ','" & lug_meaning.Text.ToString() & "','" & eng_meaning.Text.ToString() & "','" & word.Text.ToString() & "')"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.