Friday, May 28, 2010

Inserting new record into Access database with VB.Net


Imports System.Data.Odbc
Partial Class New_Customer
Inherits System.Web.UI.Page
Dim con As New OdbcConnection("Dsn=JLCB")

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim insert As String
insert = "Insert into customer values('" & TextBox0.Text & "','" & TextBox1.Text & "'," & TextBox2.Text & "," & TextBox3.Text & ",'" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "','" & TextBox7.Text & "','" & TextBox8.Text & "','" & TextBox9.Text & "','" & TextBox10.Text & "','" & TextBox11.Text & "','" & DropDownList1.Text & "')"
Dim com1 As New OdbcCommand(insert, con)
Dim x As Integer
Try
con.Open()
x = com1.ExecuteNonQuery
MsgBox("Record Inserted Sucessfully")
clear()
Catch ex As Exception
MsgBox("Please check info carefully. Make sure 'ID' provided is available or not.")
Finally
con.Close()
End Try
End Sub

No comments:

Post a Comment