TechyGirl

Who says a girl cannot be both athletic and geeky?

How to insert data into MS SQL database

February24

Dim CommandString As String = “INSERT INTO TableName VALUES (’column0′,’column1′,’column2′)”
‘assuming there is only column 0 to column 2 in the TableName

     Dim cmd As New SqlCeCommand
Dim conn As New SqlCeConnection(DBconnectionString)

‘DBConnectionString is the connection string that connects to the database

Dim cmdNewThing As New SqlCeCommand(CommandString, conn)

Try
conn.Open()
cmdNewThing.ExecuteNonQuery()

MsgBox(”The new thing has been added successfully”)

        Catch ex As Exception
MsgBox(”Error: ” & ex.Source & “: ” & ex.Message, MsgBoxStyle.OkOnly, “There is a connection error with the database. Please Check.”)
End Try

conn.Close()

posted under VB.NET | No Comments »

Updates on Wireless Fencing Scoring System

February17

Well, it’s been a while since I last update you about Wireless Fencing Scoring System. The good point is that, everybody is pouring their hard work and sweats into this project! We’re almost done with the GUI and database. Right now, all of us are concentrating on reading data from Bluetooth through Serial Port and converting it to lights on the simulator.Hopefully this will be done soon!

If you would like to know our progress in this project, feel free to visit the project’s main website.

SQL Compact Database Connection in VB.NET

February17

SQL Compact Database is often used on individual computers, often bundled with personal software. This database does not involve setting up server and usually is used for mobile applications. I would like to share with you the ways and codes to connect to SQL Compact Database using VB.NET.

1. Add the data source to your application. The SQL Compact database file ends with *.sdf. You can create this database through either Visual Studio or Microsoft SQL Server Express. Declare the connection string in the public class:

Dim DBconnectionString As String = “Data Source=|DataDirectory|\databasename.sdf”

2. Then, put this code when you want to connect to the database

    Dim cmd As New SqlCeCommand
Dim conn As New SqlCeConnection(DBconnectionString)

Dim cmdGetName As New SqlCeCommand
Dim daGetName As New SqlCeDataAdapter
Dim dsGetName As New DataSet
Dim dtGetName As New DataTable

Try
cmd.Connection = conn
conn.Open()

cmdGetFencersName = conn.CreateCommand
cmdGetFencersName.CommandText = “Put your command here”

            daGetName.SelectCommand = cmdGetName
daGetName.Fill(dsGetName, “TableName”)
dtGetName = dsGetName.Tables(”TableName”)

   ‘Now, decide how you want to display the data.
‘The following code shows you how to add the data from the data table to a combobox.

                
Dim i As Integer

                For i = 0 To dtGetName.Rows.Count - 1
cmbName.Items.Add(dtGetName.Rows(i).Item(0))
Next
cmbName.Sorted = True

Catch ex As Exception
MsgBox(”Error: ” & ex.Source & “: ” & ex.Message, MsgBoxStyle.OkOnly, “There is a connection error with the database. Please Check.”)
End Try

conn.Close()

I hope that helps! =)

posted under VB.NET | No Comments »
« Older Entries