 |
|
ผมมีปัญหาครับรันแล้วข้อมูลไม่ขึ้นเลย ไม่ติด Error ผมลองดีบัคแล้วก้ไม่มี Error อะไร และเข้าไปดูข้อมูลใน SQL ข้อมูลก้มี
Code ในส่วนของ design
Code (VB.NET)
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="Test2.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 runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="myDataGrid" runat="server" AutoGenerateColumns="False">
<Columns >
<asp:TemplateField HeaderText = "แผนก" >
<ItemTemplate>
<asp:Label id="lblDepartment_Name" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Department_name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText = "รหัสพนักงาน" >
<ItemTemplate>
<asp:Label id="lblEmployee_ID" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Employee_ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText = "ชื่อ" >
<ItemTemplate>
<asp:Label id="lblEmployee_FirstName" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Employee_FirstName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText = "นามสกุล" >
<ItemTemplate>
<asp:Label id="lblEmployee_LastName" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Employee_LastName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText = "วันที่" >
<ItemTemplate>
<asp:Label id="lblVacation_Date" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Vacation_Date") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
<asp:Button ID="Button1" runat="server" Text="Button" Width="82px" />
</div>
</form>
</body>
</html>
ส่วนของ Code ที่ดึงข้อมูลขาก SQL
Code (VB.NET)
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient
Imports System.Data.Sql
Imports System.Text
Public Class WebForm1
Inherits System.Web.UI.Page
Dim dtt As DataTable
Dim dt As DataTable
Dim objConn As SqlConnection
Dim objCmd As SqlCommand
Dim ArrTest() As String = {"INF","SD"}
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim strConnString As String
strConnString = "Server=ชื่อ server;Database=HR;Integrated Security=True"
objConn = New SqlConnection(strConnString)
objConn.Open()
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Dim dtReader As SqlDataReader
' For i As Integer = 0 To ArrTest.Length - 1
Dim sql = "select Employee.Department_Name,Employee.Employee_ID,Employee.Employee_FirstName,Employee.Employee_LastName,Time.Card_Date From Employee LEFT Join Time ON Employee.Employee_ID = Time.Employee_ID where Employee.Department_Name ='" & ArrTest(0) & "' AND Employee.Employee_Status = 'TRUE' AND Time.Card_Date = '20/5/2557'" +
" UNION" +
" select Employee.Department_Name,Employee.Employee_ID,Employee.Employee_FirstName,Employee.Employee_LastName,Emp_Vacation.Vacation_Date From Employee LEFT Join Emp_Vacation ON Employee.Employee_ID = Emp_Vacation.Employee_ID where Employee.Department_Name ='" & ArrTest(0) & "' AND Employee.Employee_Status = 'TRUE' AND Emp_Vacation.Vacation_Date = '20/5/2557'"
objCmd = New SqlCommand(sql, objConn)
dtReader = objCmd.ExecuteReader()
myDataGrid.DataSource = dtReader
myDataGrid.DataBind()
dtReader.Close()
'dt = GetData(sql, StrConnDB)
'dtt = dt
'Next
'myDataGrid.DataSource = dtt
'myDataGrid.DataBind()
End Sub
End Class
Tag : ASP, Web (ASP.NET), VB.NET, VS 2010 (.NET 4.x)
|
|
 |
 |
 |
 |
Date :
2014-08-04 10:26:40 |
By :
theblue02 |
View :
917 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |