[ VB 2008 ] 데이터베이스예제 .sdf 본문

[PL]/VB & VB.NET

[ VB 2008 ] 데이터베이스예제 .sdf

객과 함께. 2010. 1. 19. 00:24

Imports System
Imports System.Data
Imports System.Data.SqlServerCe

Public Class Form1

    Dim strDB As String = "Data Source = 경로명 및 파일명.sdf"

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim ai As Integer

        If TextBox1.Text <> "" Then

            If ai = 1 Then Exit Sub

            Dim Conn As SqlCeConnection = New SqlCeConnection(strDB)
            Conn.Open()

            Dim sqlcmd As SqlCeCommand = New SqlCeCommand()
            sqlcmd.Connection = Conn

            Dim tran As SqlCeTransaction = Conn.BeginTransaction()
            sqlcmd.Transaction = tran

            sqlcmd.CommandText = "INSERT INTO TableBlog VALUES( '1' , '" & TextBox1.Text & "')"
            sqlcmd.ExecuteNonQuery()

            tran.Commit()
            Conn.Close()
            TextBox1.Text = ""
            ai = 0
        Else

            TextBox1.Text = "입력할 데이터 입력 하세요"
            ai = 1
            Exit Sub
        End If

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Text = "테이텁;이스 예제"
        Button1.Text = "저 장"
    End Sub
End Class

'[PL] > VB & VB.NET' 카테고리의 다른 글

ManagementPath.RelativePath 속성  (0) 2010.06.26
[VB 2008] XML 문서예제  (0) 2010.01.19
[ VB 2008 ] COLOR View예제.  (0) 2010.01.11
[ VB 2008 ] TreeView 예제  (0) 2010.01.10
[VB 2008] 아래 세개의 프로그래을 하나로 한 것.  (0) 2010.01.09