Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > บทความจากสมาชิก > VB.NET Connect Database กับ VB แบบง่ายๆ



 
Clound SSD Virtual Server

VB.NET Connect Database กับ VB แบบง่ายๆ

VB.NET Connect Database กับ VB แบบง่ายๆ Dataset , Connect , isnumeric

form แสดง datagirdview

https://sites.google.com/site/thebunwangs/bug-defect-error/karchidatagridviewnivisualbasic2008

การใช้ Girdview
Imports System.Data
Imports System.Data.SqlClient
Public Class Form3
    Dim Conn As New SqlConnection
    Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Form1.Hide()
        Form2.Close()
        Form4.Close()
        DataGridView1.Refresh()
        Me.ProductTableAdapter.Fill_product(Me.DataSet1.product)
        DataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.Bisque
        DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells
        'TODO: This line of code loads data into the 'DataSet1.product' table. You can move, or remove it, as needed.


    End Sub
    Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
        If (DataGridView1.CurrentRow.Cells(0).Selected) Then
            Button3.Enabled = True
            Button4.Enabled = True
        End If
        'TextBox1.Text = DataGridView1.CurrentRow.Cells(1).Value.ToString()
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Form2.Show()
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Form4.Show()
    End Sub

    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        If MsgBox("แน่ใจหรือไม่จะลบสินค้านี้ ?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "ยืนยันการออกจากโปรแกรม") = MsgBoxResult.Yes Then

            With Conn
                If .State = ConnectionState.Open Then .Close()

                .ConnectionString = "Data Source=Dung-PC\sqlexpress; " & _
                  "Integrated Security=True; Initial Catalog=test_db; " & _
                  "Persist Security Info=False"

                .Open()

                If .State = 1 Then MsgBox("OK")

            End With

            Dim cmd As New SqlCommand("DELETE from product where product_id=" & DataGridView1.CurrentRow.Cells(0).Value.ToString() & "", Conn)
            If cmd.ExecuteNonQuery() Then
                MsgBox("Delete Product Success")
                Form1.reloadForm3()
            End If

        End If
    End Sub
End Class



connect db และการใช้ cmd

Connect DB
With Conn
                If .State = ConnectionState.Open Then .Close()

                .ConnectionString = "Data Source=name-server\sqlexpress; " & _
                  "Integrated Security=True; Initial Catalog=test_db; " & _
                  "Persist Security Info=False"

                .Open()

                If .State = 1 Then MsgBox("OK")

            End With

            Dim cmd As New SqlCommand("DELETE from product where product_id=" & DataGridView1.CurrentRow.Cells(0).Value.ToString() & "", Conn)
            If cmd.ExecuteNonQuery() Then
                MsgBox("Delete Product Success")
                Form1.reloadForm3()
            End If







   
Share
Bookmark.   

  By : StePzDJM
  Article : บทความเป็นการเขียนโดยสมาชิก หากมีปัญหาเรื่องลิขสิทธิ์ กรุณาแจ้งให้ทาง webmaster ทราบด้วยครับ
  Score Rating :
  Create Date : 2012-09-21
  Download : No files
Sponsored Links
ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 03
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่