 |
|
|
 |
 |
|
คุณก็สร้าง query select ข้อมูลมาโดนส่ง where วันที่ไปไปสองวัน
คุณต้องบอกละเอียดกว่านี้จะได้เขียนตัวอย่างให้ดุได้คับ
|
 |
 |
 |
 |
Date :
2009-09-25 17:26:40 |
By :
besttooo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
นี่คือโค้ดเท่าที่เขียนได้ค่ะ ขอบคุณนะค่ะ
Code (VB.NET)
Dim conStr As String = "Data Source=.\SQLEXPRESS;AttachDbFilename='C:\Visual Studio 2008\Projects\PROJECT MORYA.mdf';Integrated Security=True;Connect Timeout=30;User Instance=True"
Dim conn As New SqlConnection(conStr)
conn.Open()
Dim sql As String = "Select date,pharmacist_name,supplier_name,product_serialno,product_name,quantity,causes From returndetail"
Dim cmd As New SqlCommand(sql, conn)
Dim adapter As New SqlDataAdapter(cmd)
Dim data As New DataSet()
adapter.Fill(data, "returndetail")
DataGridView1.DataSource = data.Tables("returndetail")
DataGridView1.Columns("date").HeaderText = "วันที่คืนสินค้า"
DataGridView1.Columns("pharmacist_name").HeaderText = "ชื่อเภสัชกร"
DataGridView1.Columns("supplier_name").HeaderText = "ชื่อตัวแทนจำหน่าย"
DataGridView1.Columns("product_serialno").HeaderText = "รหัสสินค้า"
DataGridView1.Columns("product_name").HeaderText = "ชื่อสินค้า"
DataGridView1.Columns("quantity").HeaderText = "จำนวน"
DataGridView1.Columns("causes").HeaderText = "สาเหตุที่คืน"
sb.Remove(0, sb.Length) '' คำสั่ง Query ข้อมูล
sb.Append("Select date,pharmacist_name,supplier_name,product_serialno,product_name,quantity,causes From returndetail")
sb.Append(" Where (date Between '" & DateTimePicker1.Value.Month.ToString & " / " & DateTimePicker1.Value.Day.ToString & " / " & DateTimePicker1.Value.Year.ToString & "' And '" & DateTimePicker2.Value.Month.ToString & " / " & DateTimePicker2.Value.Day.ToString & " / " & DateTimePicker2.Value.Year.ToString & "')")
strSql = sb.ToString() '' เก็บใน String
cm = New SqlCommand()
With cm
.CommandText = strSql
.Connection = cn
dr = .ExecuteReader()
End With
If dr.HasRows Then ''check dr
Dim dtSql As DataTable
dtSql = New DataTable()
dtSql.Load(dr)
With DataGridView1
.DataSource = dtSql
End With
Else
MessageBox.Show("ช่วงเวลาที่คุณระบุ ไม่มีรายการคืน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
DateTimePicker1.Focus()
End If
dr.Close()
|
 |
 |
 |
 |
Date :
2009-09-25 18:33:20 |
By :
srilai |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอนนี้คุณได้ข้อมูลมาแล้วใช่ไหมครับ แล้วจะเอาข้อมูลที่ได้มาลง ใน grid ใช่อะป่าวคับ
|
 |
 |
 |
 |
Date :
2009-09-25 18:47:57 |
By :
besttooo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณก็สั่ง
DataGridview1.datasource = stSql
DataGridview1.Databind()
แล้วหน้า design ที่ gridview ดู code ตัวอย่างแนวๆนี้นะครับ
Code (ASP)
<%
<asp:GridView ID="gvDetail" runat="server" AllowPaging="True" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="ProductSeq" Font-Size="10pt" ForeColor="#333333" ShowFooter="True" Width="100%" OnPageIndexChanging="gvDetail_PageIndexChanging" EmptyDataText="No Data" >
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<Columns>
<asp:TemplateField HeaderText="Edit">
<HeaderStyle HorizontalAlign="Center" Width="30px"/>
<ItemTemplate>
<asp:ImageButton ID="btnEdit" Width="20px" Height="20px" runat="server" ImageUrl='img/001_45.gif' ToolTip="Edit" OnClick="btnEdit_Click" CommandArgument='<%# DataBinder.Eval(Container, "DataItem.ProductSeq").ToString() %>' CausesValidation="false"/>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center"/>
</asp:TemplateField>
<asp:TemplateField HeaderText="Rack Type">
<HeaderStyle HorizontalAlign="Center" Width="200px"/>
<ItemTemplate>
<asp:Label ID="lblRackType" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.ProductCode") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center"/>
</asp:TemplateField>
<asp:TemplateField HeaderText="Origin">
<HeaderStyle HorizontalAlign="Center"/>
<ItemTemplate>
<asp:Label ID="lblOrigin" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.OriginCountry") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center"/>
</asp:TemplateField>
<asp:TemplateField HeaderText="Curr. Code">
<HeaderStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:Label ID="lblCurrencyCode" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.InvoiceCurrency") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Unit Price">
<HeaderStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:Label ID="lblUnitPrice" runat="server" Text='<%# String.Format("{0,-12:N5}", DataBinder.Eval(Container, "DataItem.UnitPrice")) %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Qty">
<HeaderStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:Label ID="lblQty" runat="server" Text='<%# String.Format("{0,-12:N5}",DataBinder.Eval(Container, "DataItem.InvoiceQty")) %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Weight Per Unit">
<HeaderStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:Label ID="lblWeight" runat="server" Text='<%# String.Format("{0,-12:N5}",DataBinder.Eval(Container, "DataItem.WeightPerUnit")) %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
</Columns>
</asp:GridView>
%>
|
 |
 |
 |
 |
Date :
2009-09-25 18:52:12 |
By :
besttooo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
DataBinder.Eval(Container, "DataItem.ProductCode")
ProductCode คือชื่อฟิวใน datable dtSql คุณก็เปลี่ยนตามชื่อของคุณครับ
DataGridview1.datasource = stSql อันนี้ผมพิมพ์ผิดต้องเป็น dtSql ครับ
|
 |
 |
 |
 |
Date :
2009-09-25 18:54:06 |
By :
besttooo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอเป็นโค้ด vb.net ได้ไหมค่ะ asp ไม่มีความรู้เลย ขอบคุณค่ะ
|
 |
 |
 |
 |
Date :
2009-09-25 20:06:45 |
By :
srilai |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันเป็น window app หรือ web app
ขอรายละเอียดด้วยจะได้ช่วยได้ถูกต้องครับ
|
 |
 |
 |
 |
Date :
2009-09-25 20:36:52 |
By :
otomokung |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เป็น window app ค่ะ
|
 |
 |
 |
 |
Date :
2009-09-25 22:36:45 |
By :
srilai |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมนึกว่า เว็บแอฟ กำๆ โทดทีนะ
|
 |
 |
 |
 |
Date :
2009-09-26 11:22:21 |
By :
besttooo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|