ยินดีต้อนรับคุณ, บุคคลทั่วไป กรุณา เข้าสู่ระบบ หรือ ลงทะเบียน

เข้าสู่ระบบด้วยชื่อผู้ใช้ รหัสผ่าน และระยะเวลาในเซสชั่น

ThaiSEOBoard.comพัฒนาเว็บไซต์Programmingถามเรื่อง asp.net หน่อยครับ ช่วยที
หน้า: [1]   ลงล่าง
พิมพ์
ผู้เขียน หัวข้อ: ถามเรื่อง asp.net หน่อยครับ ช่วยที  (อ่าน 638 ครั้ง)
0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้
com_sc091
Newbie
*

พลังน้ำใจ: 0
ออฟไลน์ ออฟไลน์

กระทู้: 9



ดูรายละเอียด
« เมื่อ: 23 เมษายน 2010, 15:52:54 »

อยากทราบวิธีการ เอาข้อมูล excel เอามาแสดงใน texbox
แล้วก็ เอาข้อมูลใน excel เอามาแสดงใน gridview ครับ

อยากรู้จริงนะครับ ได้โปรดบอกผมทีครับ

 wanwan006 wanwan006 wanwan006
บันทึกการเข้า
yukasung
คนรักเสียว
*

พลังน้ำใจ: 1
ออฟไลน์ ออฟไลน์

กระทู้: 138



ดูรายละเอียด เว็บไซต์
« ตอบ #1 เมื่อ: 23 เมษายน 2010, 16:26:08 »

<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Oledb" %>

<script language="VB" runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
Dim myDataset As New DataSet()

''You can also use the Excel ODBC driver I believe - didn''t try though
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:exceltest.xls;" & _
"Extended Properties=""Excel 8.0;"""

''You must use the $ after the object you reference in the spreadsheet
Dim myData As New OledbDataAdapter("SELECT * FROM [Sheet1$]", strConn)
myData.TableMappings.Add("Table", "ExcelTest")
myData.Fill(myDataset)

DataGrid1.DataSource = myDataset.Tables(0).DefaultView
DataGrid1.DataBind()
End Sub
</script>

<html>
<head></head>
<body>
<p><asp:Label id=Label1 runat="server">SpreadSheetContents:</asp:Label></p>
<asp:DataGrid id=DataGrid1 runat="server"/>
</body>
</html>

C# Syntax

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System" %>


<script language="C#" runat="server">
protected void Page_Load(Object Src, EventArgs E)
{
string strConn;
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" 
"Data Source=C:\exceltest.xls;" 
"Extended Properties=Excel 8.0;";
//You must use the $ after the object you reference in the spreadsheet
OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM [Sheet1$]",strConn);

DataSet myDataSet = new DataSet();
myCommand.Fill(myDataSet, "ExcelInfo");
DataGrid1.DataSource = myDataSet.Tables["ExcelInfo"].DefaultView;
DataGrid1.DataBind();
}
</script>
<html>
<head></head>
<body>
<p><asp:Label id=Label1 runat="server">SpreadSheetContents:</asp:Label></p>
<asp:DataGrid id=DataGrid1 runat="server"/>
</body>
</html>
บันทึกการเข้า
com_sc091
Newbie
*

พลังน้ำใจ: 0
ออฟไลน์ ออฟไลน์

กระทู้: 9



ดูรายละเอียด
« ตอบ #2 เมื่อ: 23 เมษายน 2010, 17:18:35 »

มีแบบ เอาแสดงใน textbox เปล่าครับ  wanwan008 wanwan008
บันทึกการเข้า
หน้า: [1]   ขึ้นบน
พิมพ์