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 > Export ไฟล์ Excel & PDF จาก ASP.NET + Sql Server 2005 ด่วนมาก



 

Export ไฟล์ Excel & PDF จาก ASP.NET + Sql Server 2005 ด่วนมาก

 



Topic : 033764



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



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



https://www.thaicreate.com/asp.net/asp.net-export-database-to-excel-print-report-format.html

จากลิงค์ด้านบน

ถ้าหากแก้เป็น sql 2005 ทำยังไงค่ะ

ลองแก้เองแล้วก็ยังไม่สามารถทำได้ค่ะ

หากใครทราบกรุณาช่วยตอบหน่อยนะค่ะ รีบมากค่ะ



Tag : - - - -







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2009-11-02 02:21:54 By : vongole View : 2349 Reply : 7
 

 

No. 1



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



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

ลืมบอกไปค่ะ

https://www.thaicreate.com/asp.net/asp.net-export-report-database-to-pdf.html

จาก sql 2005 เป็น pdf ด้วยค่ะ


วอนผู้รู้ทั้งหลายช่วยตอยด้วยนะค่ะ
ขอบคุณมากค่ะ

ใช้ asp.net 3.5 sql 2005






Date : 2009-11-02 02:27:41 By : vongole
 


 

No. 2



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

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

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

เปลี่ยนตรง Connection น่ะครับ ดูตัวอย่างการเรียกใช้ SQL Server ได้ที่

Code (VB.NET)
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.SqlClient"%>
<%@ Page Language="VB" %>
<script runat="server">

	Dim objConn As SqlConnection
	Dim objCmd As SqlCommand

    Sub Page_Load(sender As Object, e As EventArgs)
		Dim strConnString As String
		strConnString = "Server=localhost;UID=sa;PASSWORD=;database=mydatabase;Max Pool Size=400;Connect Timeout=600;"
		objConn = New SqlConnection(strConnString)
		objConn.Open()

		BindData()
    End Sub

	Sub BindData()
		Dim strSQL As String
		strSQL = "SELECT * FROM customer"

		Dim dtReader As SqlDataReader
		objCmd = New SqlCommand(strSQL, objConn)
		dtReader = objCmd.ExecuteReader()
		
		'*** BindData to Repeater ***'
		myRepeater.DataSource = dtReader
		myRepeater.DataBind()

		dtReader.Close()
		dtReader = Nothing

	End Sub

	Sub Page_UnLoad()
		objConn.Close()
		objConn = Nothing
	End Sub


</script>
<html>
<head>
<title>ThaiCreate.Com ASP.NET - SQL Server</title>
</head>
<body>
	<form id="form1" runat="server">
    <asp:Repeater id="myRepeater" runat="server">
	<HeaderTemplate>
		<table border="1">
			<tr>
				<th>CustomerID</th>
				<th>Name</th>
				<th>Email</th>
				<th>CountryCode</th>
				<th>Budget</th>
				<th>Used</th>
			</tr>
	</HeaderTemplate>
	<ItemTemplate>
		<tr>
			<td align="center"><asp:Label id="lblCustomerID" runat="server" Text='<%#Container.DataItem("CustomerID") %>'></asp:Label></td>
			<td><asp:Label id="lblName" runat="server" Text='<%#Container.DataItem("Name") %>'></asp:Label></td>
			<td><asp:Label id="lblEmail" runat="server" Text='<%#Container.DataItem("Email") %>'></asp:Label></td>
			<td align="center"><asp:Label id="lblCountryCode" runat="server" Text='<%#Container.DataItem("CountryCode") %>'></asp:Label></td>
			<td align="right"><asp:Label id="lblBudget" runat="server" Text='<%#Container.DataItem("Budget") %>'></asp:Label></td>
			<td align="right"><asp:Label id="lblUsed" runat="server" Text='<%#Container.DataItem("Used") %>'></asp:Label></td>
		</tr> 		
	</ItemTemplate>
	<AlternatingItemTemplate>
		<tr bgcolor="#e8e8e8">
			<td align="center"><asp:Label id="lblCustomerID" runat="server" Text='<%#Container.DataItem("CustomerID") %>'></asp:Label></td>
			<td><asp:Label id="lblName" runat="server" Text='<%#Container.DataItem("Name") %>'></asp:Label></td>
			<td><asp:Label id="lblEmail" runat="server" Text='<%#Container.DataItem("Email") %>'></asp:Label></td>
			<td align="center"><asp:Label id="lblCountryCode" runat="server" Text='<%#Container.DataItem("CountryCode") %>'></asp:Label></td>
			<td align="right"><asp:Label id="lblBudget" runat="server" Text='<%#Container.DataItem("Budget") %>'></asp:Label></td>
			<td align="right"><asp:Label id="lblUsed" runat="server" Text='<%#Container.DataItem("Used") %>'></asp:Label></td>
		</tr>			
	</AlternatingItemTemplate>
	</asp:Repeater>
	</form>
</body>
</html>


ASP.NET & SQL Server Get Data Record
Date : 2009-11-02 06:08:38 By : webmaster
 

 

No. 3



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

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

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

เดียวเขียนให้เลยดีกว่าครับ

อันนี้ ASP.NET & Excel & SQL Server 200x ครับ

<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.SqlClient"%>
<%@ Import Namespace="Excel"%>
<%@ Import Namespace="System.IO"%>
<%@ Page Language="VB" %>
<script runat="server">

    Sub Page_Load(sender As Object, e As EventArgs)		
        Dim objConn As New SqlConnection
	Dim dtAdapter As SqlDataAdapter 
	Dim dt As New System.Data.DataTable       

	Dim strConnString As String
	strConnString = "Server=localhost;UID=sa;PASSWORD=;database=mydatabase;Max Pool Size=400;Connect Timeout=600;"
	objConn = New SqlConnection(strConnString)
	objConn.Open()

	Dim strSQL As String		
	strSQL = "SELECT * FROM customer"
	
	'*** Create DataTable ***'	
	dtAdapter = New SqlDataAdapter(strSQL, objConn)
	dtAdapter.Fill(dt)
		
		'*** Export To Excel ***'
        Dim FileName As String
        FileName = "MyXls/MyExcel.xls"

        '*** Create Excel.Application ***'
        Dim xlApp As New Excel.Application
        Dim xlSheet1 As Excel.Worksheet
        Dim xlBook As Excel.Workbook	

		Dim i As Integer
		Dim intRows As Integer

		xlBook = xlApp.Workbooks.Add()
		xlBook.Application.Visible = False

		'*** Create Sheet 1 ***'
		xlSheet1 = xlBook.Worksheets(1)
		xlSheet1.Name = "My Sheet1"

		'*** Width & Height (A1:A1) ***'
		With xlApp.ActiveSheet.Range("A1:A1")
			.ColumnWidth = 10.0
		End With
		With xlApp.ActiveSheet.Range("B1:B1")
			.ColumnWidth = 13.0
		End With
		With xlApp.ActiveSheet.Range("C1:C1")
			.ColumnWidth = 23.0
		End With
		With xlApp.ActiveSheet.Range("D1:D1")
			.ColumnWidth = 12.0
		End With
		With xlApp.ActiveSheet.Range("E1:E1")
			.ColumnWidth = 13.0
		End With
		With xlApp.ActiveSheet.Range("F1:F1")
			.ColumnWidth = 12.0
		End With

		With xlApp.ActiveSheet.Range("A1:F1")
			.BORDERS.Weight = 1
			.MergeCells = True
			.Font.Bold = True
			.Font.Size = 20
			.HorizontalAlignment = -4108
		End With
			With xlApp.ActiveSheet.Cells(1,1)
			.Value = "Customer Report"
		End With

		'*** Header ***'
		With xlApp.ActiveSheet.Cells(2,1)
			.Value = "CustomerID"
			.Font.Bold = True
			.VerticalAlignment = -4108
			.HorizontalAlignment = -4108
			.BORDERS.Weight = 1
		End With
		With xlApp.ActiveSheet.Cells(2,2)
			.Value = "Name"
			.Font.Bold = True
			.VerticalAlignment = -4108
			.HorizontalAlignment = -4108
			.BORDERS.Weight = 1
		End With
		With xlApp.ActiveSheet.Cells(2,3)
			.Value = "Email"
			.Font.Bold = True
			.VerticalAlignment = -4108
			.HorizontalAlignment = -4108
			.BORDERS.Weight = 1
		End With
		With xlApp.ActiveSheet.Cells(2,4)
			.Value = "CountryCode"
			.Font.Bold = True
			.VerticalAlignment = -4108
			.HorizontalAlignment = -4108
			.BORDERS.Weight = 1
		End With
		With xlApp.ActiveSheet.Cells(2,5)
			.Value = "Budget"
			.Font.Bold = True
			.VerticalAlignment = -4108
			.HorizontalAlignment = -4108
			.BORDERS.Weight = 1
		End With
		With xlApp.ActiveSheet.Cells(2,6)
			.Value = "Used"
			.Font.Bold = True
			.VerticalAlignment = -4108
			.HorizontalAlignment = -4108
			.BORDERS.Weight = 1
		End With
		'***********'

		intRows = 3
		For i = 0 To dt.Rows.Count - 1
			'*** Detail ***'
			With xlApp.ActiveSheet.Cells(intRows,1)
				.Value = dt.Rows(i)("CustomerID")
				.BORDERS.Weight = 1
				.HorizontalAlignment = -4108
			End With
			With xlApp.ActiveSheet.Cells(intRows,2)
				.Value = dt.Rows(i)("Name")
				.BORDERS.Weight = 1
			End With
			With xlApp.ActiveSheet.Cells(intRows,3)
				.Value = dt.Rows(i)("Email")
				.BORDERS.Weight = 1
			End With
			With xlApp.ActiveSheet.Cells(intRows,4)
				.Value = dt.Rows(i)("CountryCode")
				.HorizontalAlignment = -4108
				.BORDERS.Weight = 1
			End With
			With xlApp.ActiveSheet.Cells(intRows,5)
				.Value = FormatNumber(dt.Rows(i)("Budget"),2)
				.BORDERS.Weight = 1
			End With
			With xlApp.ActiveSheet.Cells(intRows,6)
				.Value = FormatNumber(dt.Rows(i)("Used"),2)
				.BORDERS.Weight = 1
			End With
			intRows = intRows + 1
		Next
	
        '*** If Files Already Exist Delete files ***'
		Dim MyFile As New FileInfo(Server.MapPath(FileName))
		If MyFile.Exists Then
			MyFile.Delete()
		End IF
		MyFile = Nothing

        '*** Save Excel ***'
        'xlSheet1.PrintOut 1 '*** Print to printer ***'
        xlSheet1.SaveAs(Server.MapPath(FileName))
        xlApp.Quit()

        '*** Quit and Clear Object ***'
        xlSheet1 = Nothing
        xlBook = Nothing
        xlApp = Nothing

		'*** End Export To Excel ***'

		Me.lblText.Text = "Excel Created <a href="& FileName & ">Click here</a> to Download."

		dtAdapter = Nothing
		objConn.Close()
		objConn = Nothing

	End Sub


</script>
<html>
<head>
<title>ThaiCreate.Com ASP.NET - Excel Application</title>
</head>
<body>
	<form id="form1" runat="server">	
	<asp:Label id="lblText" runat="server"></asp:Label>
	</form>
</body>
</html>

Date : 2009-11-02 06:11:51 By : webmaster
 


 

No. 4



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

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

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

อันนี้ ASP.NET & PDF & SQL Server 200x ครับ

<%@ Import Namespace="PdfSharp"%>
<%@ Import Namespace="PdfSharp.Drawing"%>
<%@ Import Namespace="PdfSharp.Pdf"%>
<%@ Import Namespace="PdfSharp.Pdf.IO"%>

<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.SqlClient"%>

<%@ Page Language="VB" %>
<script runat="server">
    Sub Page_Load(sender As Object, e As EventArgs)				
	' Create a new PDF document
	Dim DocPDF As PdfDocument = New PdfDocument

	' Create an empty page
	Dim objPage As PdfPage = DocPDF.AddPage

	' Get an XGraphics object for drawing
	Dim gfx As XGraphics = XGraphics.FromPdfPage(objPage)

	' Create a font
	Dim font1 As XFont = New XFont("Verdana", 15, XFontStyle.Bold)
	Dim font2 As XFont = New XFont("Tahoma", 8, XFontStyle.Bold)
	Dim font3 As XFont = New XFont("Tahoma", 8, 0)

	' Draw the text
	gfx.DrawString("My Customer", font1, XBrushes.Black, _
	New XRect(0, 50, objPage.Width.Point, objPage.Height.Point), XStringFormats.TopCenter)

	' Draw the text
	gfx.DrawString("CustomerID", font2, XBrushes.Black, 65, 80, XStringFormats.TopLeft)
	gfx.DrawString("Name", font2, XBrushes.Black, 140, 80, XStringFormats.TopLeft)
	gfx.DrawString("Email", font2, XBrushes.Black, 215, 80, XStringFormats.TopLeft)
	gfx.DrawString("CountryCode", font2, XBrushes.Black, 365, 80, XStringFormats.TopLeft)
	gfx.DrawString("Budget", font2, XBrushes.Black, 425, 80, XStringFormats.TopLeft)
	gfx.DrawString("Used", font2, XBrushes.Black, 485, 80, XStringFormats.TopLeft)
		
		' Line
        Dim pen As XPen = New XPen(XColor.FromArgb(0, 0, 0))
        gfx.DrawLine(pen, New XPoint(65, 78), New XPoint(520, 78))
		gfx.DrawLine(pen, New XPoint(65, 90), New XPoint(520, 90))

		' Customer From Database (Start)

		Dim objConn As New SqlConnection
		Dim objCmd As New SqlCommand
		Dim dtAdapter As New SqlDataAdapter

		Dim ds As New DataSet
		Dim dt As DataTable
		Dim strConnString,strSQL As String

		strConnString = "Server=localhost;UID=sa;PASSWORD=;database=mydatabase;Max Pool Size=400;Connect Timeout=600;"
		strSQL = "SELECT * FROM customer"

		objConn.ConnectionString = strConnString
		With objCmd
			.Connection = objConn
			.CommandText = strSQL
			.CommandType = CommandType.Text
		End With
		dtAdapter.SelectCommand = objCmd

		dtAdapter.Fill(ds)
		dt = ds.Tables(0)

		dtAdapter = Nothing
		objConn.Close()
		objConn = Nothing

		Dim intLine As Integer = 90
		Dim i As Integer

		For i = 0 To dt.Rows.Count - 1
			gfx.DrawString(dt.Rows(i)("CustomerID"), font3, XBrushes.Black, 65, intLine, XStringFormats.TopLeft)
			gfx.DrawString(dt.Rows(i)("Name"), font3, XBrushes.Black, 140, intLine, XStringFormats.TopLeft)
			gfx.DrawString(dt.Rows(i)("Email"), font3, XBrushes.Black, 215, intLine, XStringFormats.TopLeft)
			gfx.DrawString(dt.Rows(i)("CountryCode"), font3, XBrushes.Black, 365, intLine, XStringFormats.TopLeft)
			gfx.DrawString(dt.Rows(i)("Budget"), font3, XBrushes.Black, 425, intLine, XStringFormats.TopLeft)
			gfx.DrawString(dt.Rows(i)("Used"), font3, XBrushes.Black, 485, intLine, XStringFormats.TopLeft)
			intLine = intLine + 10
		Next
		
		' Customer From Database (End)

		' Save the document...
		Dim FileName As String = "MyPDF/PdfDoc.pdf"
		DocPDF.Save(Server.MapPath(FileName))

		DocPDF.Close()
		DocPDF = Nothing

		Me.lblText.Text = "PDF Created <a href=" & FileName & ">click here</a> to view"

	End Sub

</script>
<html>
<head>
    <title>ThaiCreate.Com ASP.NET - Send Mail</title>
</head>
<body>
	<form id="form1" runat="server">
		<asp:Label id="lblText" runat="server"></asp:Label>
	</form>
</body>
</html>

Date : 2009-11-02 06:14:36 By : webmaster
 


 

No. 5



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



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

ขอบคุณมากค่ะ
Date : 2009-11-03 15:14:26 By : vongole
 


 

No. 6



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



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

*-*
Date : 2009-11-03 15:17:38 By : vongole
 


 

No. 7



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



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


Instance failure. มัน เป็นอย่างงี้อะค๊ะ



strConnString = "Server=.\\SQLEXPRESS;UID=dbUser;PASSWORD=dbPass;database=ServicesMSDB;Max Pool Size=400;Connect Timeout=600;"
strSQL = "SELECT * FROM customer"

objConn.ConnectionString = strConnString
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
dtAdapter.SelectCommand = objCmd

dtAdapter.Fill(ds)<<<<<< ตรงนนี้ค๊ะ

dt = ds.Tables(0)

dtAdapter = Nothing
Date : 2010-02-18 01:07:49 By : t_tul
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : Export ไฟล์ Excel & PDF จาก ASP.NET + Sql Server 2005 ด่วนมาก
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 04
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 อัตราราคา คลิกที่นี่