Mistery1
Apr 29, 2009, 03:27 AM
Hi there,
I have the ffg code so far, which inserts info into the database. But how do I go about inserting/ writing code to insert a surname like O'Reily (take not of the aprostrophe) into the database.
Imports System.Data.OleDb
Public Class Form1
Public cn As OleDbConnection
'Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
Dim icount As Integer
Dim str As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Mogie\Desktop\Emp.mdb;")
cn.Open()
str = "insert into table1 values(" & CInt(EmpNo.Text) & ",'" & Ename.Text & "','" & Department.Text & "')"
'string stores the command and CInt is used to convert number to string
cmd = New OleDbCommand(str, cn)
icount = cmd.ExecuteNonQuery
MessageBox.Show(icount)
'displays number of records inserted
cn.Close()
End Sub
End Class
I have the ffg code so far, which inserts info into the database. But how do I go about inserting/ writing code to insert a surname like O'Reily (take not of the aprostrophe) into the database.
Imports System.Data.OleDb
Public Class Form1
Public cn As OleDbConnection
'Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
Dim icount As Integer
Dim str As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Mogie\Desktop\Emp.mdb;")
cn.Open()
str = "insert into table1 values(" & CInt(EmpNo.Text) & ",'" & Ename.Text & "','" & Department.Text & "')"
'string stores the command and CInt is used to convert number to string
cmd = New OleDbCommand(str, cn)
icount = cmd.ExecuteNonQuery
MessageBox.Show(icount)
'displays number of records inserted
cn.Close()
End Sub
End Class