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,028

HOME > .NET Framework > Forum > ตอนนี้เริ่มทำ asp.net เป็นครั้งแรกเลยไม่รู้ว่าจะทำอย่างไรคือถ้าเป็นphp จะใช้ include ไฟล์มาแล้ว



 

ตอนนี้เริ่มทำ asp.net เป็นครั้งแรกเลยไม่รู้ว่าจะทำอย่างไรคือถ้าเป็นphp จะใช้ include ไฟล์มาแล้ว

 



Topic : 074320



โพสกระทู้ ( 515 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook



แล้วถ้าเป็น asp.net จะต้องใช้คำว่าอะไรค่ะคือไม่รู้ว่าจะต้องเขียนอย่างไรค่ะ
Code (ASP)
<!--#include file="connect.aspx"--> // ใส่แล้วerror ค่ะ
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="login.aspx.vb" Inherits="WebApplication2.WebForm1" %>

<!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 id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">   
    <asp:Label ID="Label1" runat="server" Text="ชื่อผู้ใช้ :"></asp:Label>&nbsp;
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <br />
    <br />
    <asp:Label ID="Label2" runat="server" Text="รหัสผ่าน :"></asp:Label>
       
    <input id="Password1" type="password" /><p>
        <input id="Submit1" type="submit" value="submit" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <input id="Reset1" type="reset" value="reset" /></p>
       
    </form>
</body>
</html>




Tag : .NET, MySQL, VB.NET









ประวัติการแก้ไข
2012-02-22 14:58:38
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-02-22 14:52:19 By : deedee2338 View : 1624 Reply : 14
 

 

No. 1



โพสกระทู้ ( 32 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

ต้องเขียนที่ Codebehide ครับ
ที่เป็นนามสกุล login.aspx.vb
แล้วค่อย New Object เข้ามา




















www.irobust.co.th
Advance Training Center








ประวัติการแก้ไข
2012-02-22 15:06:35
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-02-22 15:01:33 By : misteryou
 


 

No. 2



โพสกระทู้ ( 515 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

ตอนนี้เขียนอยู่ในส่วน login.aspx.vb แล้วแต่ไม่ได้ค่ะ
Code (ASP)
<#include file="connect.aspx"-->
Public Class WebForm1
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Session.Timeout = 60
        Session("SiteName") = ""
        Session("Name") = ""
        Response.Write("Session Created<br><br>")
        Response.Write("<a href=ASPSession2.asp>Check Session</a>")
    End Sub
End Class

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-02-22 15:05:46 By : deedee2338
 

 

No. 3



โพสกระทู้ ( 32 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

คือที่ผมเข้าใจน่าจะเขียนเก็บไว้ใน Folder App_Code
แล้วสร้าง Class Connect Datatbase
แล้วเวลาจะเรียกใช้ค่อย new object
ในเว็บนี้มีวิธีการทำลองหาดูครับ



www.irobust.co.th
Advance Training Center
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-02-22 15:13:58 By : misteryou
 


 

No. 4



โพสกระทู้ ( 11,835 )
บทความ ( 10 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์


เขียนตัว connect เป็น class ไว้ครับ ไม่ใช่เขียนแบบนั้น หรือถ้าไม่อยากเขียนใหม่ก็อ้างด้วย namespace
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-02-22 15:14:08 By : ikikkok
 


 

No. 5



โพสกระทู้ ( 515 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

สร้างแบบนี้เปล่าค่ะคือทำแล้วค่า select แล้วค่าไม่ออกค่ะ
ลองทำตามตัวอย่างhttps://www.thaicreate.com/asp.net/asp.net-mysql-database-class.html copy ทุกอย่างค่ะแต่ไม่รู้ทำไม error ค่ะ
clsDatabase.vb
Code (ASP)
Imports System.Data
Imports MySql.Data.MySqlClient
Imports System.Configuration
Public Class clsDatabase
    Private objConn As MySqlConnection
    Private objCmd As MySqlCommand
    Private Trans As MySqlTransaction
    Private strConnString As String

    Public Sub New()
        strConnString = System.Configuration.ConfigurationSettings.AppSettings("ConnectionString") // error ตรงนี้ค่ะ
    End Sub

    Public Function QueryDataReader(ByVal strSQL As String) As MySqlDataReader
        Dim dtReader As MySqlDataReader
        objConn = New MySqlConnection
        With objConn
            .ConnectionString = strConnString
            .Open()
        End With
        objCmd = New MySqlCommand(strSQL, objConn)
        dtReader = objCmd.ExecuteReader()
        Return dtReader '*** Return DataReader ***'
    End Function

Code (ASP)
<%@ Import Namespace="System.Data"%> // erro ตรงนี้ค่ะ
<%@ Import Namespace="MySql.Data.MySqlClient"%>
<%@ Page Language="VB" %>

<script runat="server">
	
	Dim clsDB As New clsDatabase
    Sub Page_Load(sender As Object, e As EventArgs)	
        Call myDataReader()
        Call myDataSet()
        Call myDataTable()
        Call myQueryExecuteScalar()
        Call myExecuteNonQuery()
        Call myExecuteTransaction()	
	End Sub


error แบบนีค่ะ
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30002: Type 'clsDatabase' is not defined.
Source Error:
Line 5: <script runat="server">
Line 6:
Line 7: Dim clsDB As New clsDatabase
Line 8: Sub Page_Load(sender As Object, e As EventArgs)
Line 9: Call myDataReader()


ประวัติการแก้ไข
2012-02-22 16:57:19
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-02-22 15:46:10 By : deedee2338
 


 

No. 6



โพสกระทู้ ( 515 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

รบกวนด้วยค่ะไม่รู้ทำไมถึง error ค่ะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-02-23 08:29:42 By : deedee2338
 


 

No. 7



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

แนะนำให้คุณเขียนบน Visual Studio ครับ ในรูปแบบของ Code Behind ครับ และใน .NET ไม่ต้อง Include ครับ ใน Project เดียวกัน สามรรถ New Class ขึ้นมาได้ทันทีครับ

Go to : ASP.NET MySQL Database Class (Visual Studio 2005,2008,2010 - .NET 2.0,3.5,4.0)

ตัวนี้ครับ สามารถดาวน์โหลดไปรันบน Visual Studio ได้เลยครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-02-23 08:37:29 By : webmaster
 


 

No. 8



โพสกระทู้ ( 515 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

ตอนี้ก็เขียนอยู่ใน Visual Studio ค่ะ ในรูปแบบของ Code Behind ด้วยค่ะคือที่ลองคือการ copy code จะเว็บไซต์มาทำเองแค่ copy มาก็error ค่ะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-02-23 08:46:17 By : deedee2338
 


 

No. 9



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Quote:
<%@ Import Namespace="System.Data"%> // erro ตรงนี้ค่ะ
<%@ Import Namespace="MySql.Data.MySqlClient"%>
<%@ Page Language="VB" %>

<script runat="server">

Dim clsDB As New clsDatabase
Sub Page_Load(sender As Object, e As EventArgs)
Call myDataReader()
Call myDataSet()
Call myDataTable()
Call myQueryExecuteScalar()
Call myExecuteNonQuery()
Call myExecuteTransaction()
End Sub


ตัวนี้ไม่ใช่ Code Behind ครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-02-23 08:48:59 By : webmaster
 


 

No. 10



โพสกระทู้ ( 127 )
บทความ ( 0 )



สถานะออฟไลน์





ประวัติการแก้ไข
2012-02-23 09:54:24
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-02-23 09:01:40 By : fight2932
 


 

No. 11



โพสกระทู้ ( 515 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

ตอนนี้ไม่ error แล้วค่ะ แต่ค่าที่จะดึงมาจาก database ไม่ได้ค่ะ
.aspx
Code (ASP)
<%@ Page Language="vb" %>

<!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></title>
</head>
<body>
  <form id="form1" runat="server">
			<asp:DataGrid id="myDataGrid1" runat="server"></asp:DataGrid>
		
			<asp:DataGrid id="myDataGrid2" runat="server"></asp:DataGrid>
			<asp:DataGrid id="myDataGrid3" runat="server"></asp:DataGrid>
			<table style="WIDTH: 300px" border="1">
				<tr>
					<td style="WIDTH: 93px">
						<asp:Label id="lblHeaderCustomerID" runat="server" Text="CustomerID"></asp:Label></td>
					<td style="WIDTH: 213px">
						<asp:Label id="lblCustomerID" runat="server"></asp:Label></td>
				</tr>
				<tr>
					<td style="WIDTH: 93px">
						<asp:Label id="lblHeaderName" runat="server" Text="Name"></asp:Label></td>
					<td style="WIDTH: 213px">
						<asp:Label id="lblName" runat="server"></asp:Label></td>
				</tr>
				<tr>
					<td style="WIDTH: 93px">
						<asp:Label id="lblHeaderEmail" runat="server" Text="Email"></asp:Label></td>
					<td style="WIDTH: 213px; HEIGHT: 23px">
						<asp:Label id="lblEmail" runat="server"></asp:Label></td>
				</tr>
				<tr>
					<td style="WIDTH: 93px">
						<asp:Label id="lblHeaderCountryCode" runat="server" Text="CountryCode"></asp:Label></td>
					<td style="WIDTH: 213px; HEIGHT: 23px">
						<asp:Label id="lblCountryCode" runat="server"></asp:Label></td>
				</tr>
				<tr>
					<td style="WIDTH: 93px">
						<asp:Label id="lblHeaderBudget" runat="server" Text="Budget"></asp:Label></td>
					<td style="WIDTH: 213px; HEIGHT: 21px">
						<asp:Label id="lblBudget" runat="server"></asp:Label></td>
				</tr>
				<tr>
					<td style="WIDTH: 93px">
						<asp:Label id="lblHeaderUsed" runat="server" Text="Used"></asp:Label></td>
					<td style="WIDTH: 213px; HEIGHT: 21px">
						<asp:Label id="lblUsed" runat="server"></asp:Label></td>
				</tr>
			</table>
			<br>
			<asp:Label id="lblText" runat="server"></asp:Label>
	</form>
</body>
</html>

.aspx.vb
Code (ASP)
Imports System.Data
Imports MySql.Data.MySqlClient
Public Class AspNetDatabase1
    Inherits System.Web.UI.Page
    Dim clsDB As New clsDatabase
    Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        Call myDataReader()
        Call myDataSet()
        Call myDataTable()
        Call myQueryExecuteScalar()
        Call myExecuteNonQuery()
        Call myExecuteTransaction()
    End Sub


    '*** DataReader ***'
    Sub myDataReader()
        Dim strSQL As String
        Dim dtReader As MySqlDataReader
        strSQL = "SELECT * FROM customer "
        dtReader = clsDB.QueryDataReader(strSQL)
        Me.myDataGrid1.DataSource = dtReader
        Me.myDataGrid1.DataBind()

        '*** Bind Rows ***'
        'If dtReader.HasRows = True Then
        '    Me.lblCustomerID.Text = dtReader.Item("CustomerID")
        '    Me.lblName.Text = dtReader.Item("Name")
        '    Me.lblEmail.Text = dtReader.Item("Email")
        '    Me.lblCountryCode.Text = dtReader.Item("CountryCode")
        '    Me.lblBudget.Text = dtReader.Item("Budget")
        '    Me.lblUsed.Text = dtReader.Item("Used")
        'End If
        clsDB.Close()
    End Sub

    '*** DataSet ***'
    Sub myDataSet()
        Dim strSQL As String
        Dim ds As DataSet
        strSQL = "SELECT * FROM customer "
        ds = clsDB.QueryDataSet(strSQL)
        Me.myDataGrid2.DataSource = ds.Tables(0).DefaultView
        Me.myDataGrid2.DataBind()

        '*** Bind Rows ***'
        'If ds.Tables(0).Rows.Count > 0 Then
        '    Me.lblCustomerID.Text = ds.Tables(0).Rows(0)("CustomerID")
        '    Me.lblName.Text = ds.Tables(0).Rows(0)("Name")
        '    Me.lblEmail.Text = ds.Tables(0).Rows(0)("Email")
        '    Me.lblCountryCode.Text = ds.Tables(0).Rows(0)("CountryCode")
        '    Me.lblBudget.Text = ds.Tables(0).Rows(0)("Budget")
        '    Me.lblUsed.Text = ds.Tables(0).Rows(0)("Used")
        'End If
        clsDB.Close()
    End Sub

    '*** DataTable ***'
    Sub myDataTable()
        Dim strSQL As String
        Dim dt As DataTable
        strSQL = "SELECT * FROM customer "
        dt = clsDB.QueryDataTable(strSQL)
        Me.myDataGrid3.DataSource = dt
        Me.myDataGrid3.DataBind()

        '*** Bind Rows ***'
        If dt.Rows.Count > 0 Then
            Me.lblCustomerID.Text = dt.Rows(0)("CustomerID")
            Me.lblName.Text = dt.Rows(0)("Name")
            Me.lblEmail.Text = dt.Rows(0)("Email")
            Me.lblCountryCode.Text = dt.Rows(0)("CountryCode")
            Me.lblBudget.Text = dt.Rows(0)("Budget")
            Me.lblUsed.Text = dt.Rows(0)("Used")
        End If
        clsDB.Close()
    End Sub

    '*** Execute Scalar ***'
    Sub myQueryExecuteScalar()
        Dim strSQL As String
        strSQL = "SELECT MAX(Budget) FROM customer "
        Me.lblText.Text = clsDB.QueryExecuteScalar(strSQL)
        clsDB.Close()
    End Sub

    '*** ExecuteNonQuery ***'
    Sub myExecuteNonQuery()
        Dim strSQL1, strSQL2, strSQL3 As String

        '*** Insert ***'
        strSQL1 = "INSERT INTO customer (CustomerID,Name,Email,CountryCode,Budget,Used) " & _
        " VALUES('C005','Weerachai Nukitram','[email protected]','TH','200000','100000')"
        If clsDB.QueryExecuteNonQuery(strSQL1) = True Then
            '*** Condition Success ***'
        Else
            '*** Condition Error ***'
        End If
        clsDB.Close()

        '*** Update ***'
        strSQL2 = "UPDATE customer SET Budget = '3000000' WHERE CustomerID = 'C005' "
        If clsDB.QueryExecuteNonQuery(strSQL2) = True Then
            '*** Condition Success ***'
        Else
            '*** Condition Error ***'
        End If
        clsDB.Close()

        '*** Delete ***'
        strSQL3 = "DELETE FROM customer WHERE CustomerID = 'C005' "
        If clsDB.QueryExecuteNonQuery(strSQL3) = True Then
            '*** Condition Success ***'
        Else
            '*** Condition Error ***'
        End If
        clsDB.Close()
    End Sub

    '*** Execute Transaction ***'
    Sub myExecuteTransaction()
        Dim strSQL1, strSQL2, strSQL3 As String

        '*** Start Transaction ***'
        clsDB.TransStart()

        Try
            '*** Insert ***'
            strSQL1 = "INSERT INTO customer (CustomerID,Name,Email,CountryCode,Budget,Used) " & _
            " VALUES('C005','Weerachai Nukitram','[email protected]','TH','200000','100000')"
            clsDB.TransExecute(strSQL1) '*** Execute Query 1 ***'

            '*** Update ***'
            strSQL2 = "UPDATE customer SET Budget = '3000000' WHERE CustomerID = 'C005' "
            clsDB.TransExecute(strSQL2) '*** Execute Query 2 ***

            '*** Delete ***'
            strSQL3 = "DELETE FROM customer WHERE CustomerID = 'C005' "
            clsDB.TransExecute(strSQL3) '*** Execute Query 3 ***

            '*** Commit Transaction ***'
            clsDB.TransCommit()

        Catch ex As Exception
            '*** RollBack Transaction ***'
            clsDB.TransRollBack()
        End Try
        clsDB.Close()
    End Sub

End Class



ประวัติการแก้ไข
2012-02-23 14:48:19
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-02-23 09:59:41 By : deedee2338
 


 

No. 12



โพสกระทู้ ( 515 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

คือตอนนี้งงที่ว่า code บรรทัดไหนที่เรียกใช้หา web.config ที่เป็นตัวเชื่อมฐานข้อมูลค่ะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-02-23 11:03:19 By : deedee2338
 


 

No. 13



โพสกระทู้ ( 515 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

รบกวนด้วยจ้าว่าทำไมค่าใน database ทำไมถึงไม่ออกค่ะ


ประวัติการแก้ไข
2012-02-24 08:26:33
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-02-23 14:49:26 By : deedee2338
 


 

No. 14



โพสกระทู้ ( 515 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

ช่วยดูให้หน่อยค่ะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-02-24 08:28:03 By : deedee2338
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ตอนนี้เริ่มทำ asp.net เป็นครั้งแรกเลยไม่รู้ว่าจะทำอย่างไรคือถ้าเป็นphp จะใช้ include ไฟล์มาแล้ว
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 02
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 อัตราราคา คลิกที่นี่