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

Registered : 92,745

 
 
HOME > ASP.NET > ASP.NET FormView Control > ASP.NET FormView Control - MySQL Database - MySql.Data.MySqlClient

ASP.NET FormView Control - MySQL Database - MySql.Data.MySqlClient

 
 


Bookmark.   
Share
       
ASP.NET FormView & MySQL (Framework 2.0,3.5) เป็นตัวอย่างการเขียน ASP.NET เรียกใช้งาน Control ชื่อ FormView เพื่อจัดการกับฐานข้อมูล MySQL โดยใช้ NameSpace ชื่อ MySql.Data.MySqlClient พัฒนาด้วย Visual Studio 2005,2008 ซึ่ง Run บน Framework 2.0,3.5 ในรูปแบบของ Code-Behind แยกในส่วนของ Tag และ Code ไว้คนล่ะส่วน

Language Code : VB.NET || C#

Framework : 2,3,4


FormView1.aspx

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="FormView1.aspx.vb" Inherits="FormView1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>ThaiCreate.Com ASP.NET - FormView & MySQL</title>
</head>
<body>
    <form id="form1" runat="server">
 		<asp:FormView id="myFormView" runat="server"
		AllowPaging="True">
            <ItemTemplate>
			<table width="500" cellpadding="5" border="0">
				<tr>
					<td valign="top" align="center">
						<asp:Image id="Image1" runat="server"/>
						<br />
						<h2><asp:Label id="lblGalleryName" runat="server"></asp:Label></h2>
					</td>
				</tr>
			</table>
            </ItemTemplate>
		</asp:FormView>
    </form>
</body>
</html>



FormView1.aspx.vb

Imports System.Data
Imports MySql.Data.MySqlClient

Partial Class FormView1
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
		IF Not Page.IsPostBack() Then
			BindData()
		End IF
    End Sub

    Sub BindData()

		Dim objConn As MySqlConnection
		Dim objCmd As MySqlCommand
		Dim dtAdapter As New MySqlDataAdapter 
        Dim strConnString As String
        strConnString = "Server=localhost;User Id=root; Password=root; Database=mydatabase; Pooling=false"
        objConn = New MySqlConnection(strConnString)
        objConn.Open()

        Dim strSQL As String
		Dim ds As New DataSet
        strSQL = "SELECT * FROM gallery "
		objCmd = New MySqlCommand
		With objCmd
			.Connection = objConn
			.CommandText = strSQL			
			.CommandType = CommandType.Text
		End With
		dtAdapter.SelectCommand = objCmd

		dtAdapter.Fill(ds)

		'*** BindData to FormView ***'
		myFormView.DataSource = ds
		myFormView.DataBind()
		
		ds = Nothing

        objConn.Close()
        objConn = Nothing

    End Sub

    Protected Sub myFormView_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles myFormView.DataBound
        '*** Image ***'
        Dim Image1 As Image = CType(myFormView.FindControl("Image1"), Image)
        If Not IsNothing(Image1) Then
            Image1.ImageUrl = "images/" & myFormView.DataItem("Picture")
            Image1.Attributes.Add("OnClick", "window.open('images/" & myFormView.DataItem("Picture") & "')")
            Image1.Style.Add("cursor", "hand")
            Image1.ToolTip = myFormView.DataItem("GalleryName")
        End If

        '*** GalleryName ***'
        Dim lblGalleryName As Label = CType(myFormView.FindControl("lblGalleryName"), Label)
        If Not IsNothing(lblGalleryName) Then
            lblGalleryName.Text = myFormView.DataItem("GalleryName")
        End If
    End Sub

   Protected Sub myFormView_PageIndexChanging(ByVal sender As Object, ByVal e As FormViewPageEventArgs) Handles myFormView.PageIndexChanging
		myFormView.PageIndex = e.NewPageIndex
		BindData()
   End Sub

End Class


Screenshot

ASP.NET FormView & MySQL


ASP.NET & MySql.Data.MySqlClient


ASP.NET & MySQL


   
Share


ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท

ลองใช้ค้นหาข้อมูล


   
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2009-09-22 19:34:46 / 2009-09-25 12:36:41
  View : 8,140
  Download : Download  ASP.NET FormView Control - MySQL Database - MySql.Data.MySqlClient
Sponsored Links
  Download Google Chorme
 
Ads Contact : 08-1987-6107 , 08-4715-5121
Download Safari
 
Ads Contact : 08-1987-6107 , 08-4715-5121
 Sponsored Links / Related


 
ASP.NET FormView Control
Rating : View : 14,124
ASP.NET FormView Control - DataBind
Rating : View : 10,633
ASP.NET FormView Control - ItemTemplate
Rating : View : 10,707
ASP.NET FormView Control - DataBound
Rating : View : 10,397
ASP.NET FormView Control - AllowPaging
Rating : View : 8,702
ASP.NET FormView Control - XML
Rating : View : 9,145
ASP.NET FormView Control - AccessDataSource
Rating : View : 7,730
ASP.NET FormView Control - DataSet,DataTable,TableRows
Rating : View : 10,675
ASP.NET FormView Control - Edit/Update
Rating : View : 12,853
ASP.NET FormView Control - Add/Insert
Rating : View : 12,521
ASP.NET FormView & GridView Control
Rating : View : 11,065
ASP.NET FormView & DataList Control
Rating : View : 10,111
ASP.NET FormView & Visual Studio 2005,2008,2010
Rating : View : 10,442
ASP.NET FormView & GridView Control - VS 2005,2008,2010 (FX 2.0,3.5,4.0)
Rating : View : 10,985
ASP.NET FormView & DataList Control - VS 2005,2008,2010 (FX 2.0,3.5,4.0)
Rating : View : 9,018
ASP.NET FormView Control - Microsoft Access (.mdb) - System.Data.OleDb
Rating : View : 8,032
ASP.NET FormView Control - SQL Server 2000,2005,2008 - System.Data.SqlClient
Rating : View : 8,653
ASP.NET FormView Control - Oracle Database - System.Data.OracleClient
Rating : View : 7,989




Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2013 All Rights Reserved. Link : ติดแก๊ส , ติดแก๊สรถยนต์
เพื่อนบ้าน : Chevrolet , Toyota , Honda , Nissan

for Contact Us : [Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 , 084-715-5121 อัตราราคา คลิกที่นี่

Back to Top