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

HOME > .NET Framework > Forum > .NET + SQL Server พี่ครับผมช่วยดู Error ของข้อมูล long binary data ที่แสดงใน DataGridView หน่อยครับ



 

.NET + SQL Server พี่ครับผมช่วยดู Error ของข้อมูล long binary data ที่แสดงใน DataGridView หน่อยครับ

 



Topic : 034277



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



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




DataGridViewError

TableWithShape

ผมได้ทำการ Select ข้อมูลจากตารางในฐานข้อมูลซึ่งมี column shape เก็บข้อมูลชนิด long binary data
พอนำมาแสดงใน DataGrid View ก็เกิด error รูปครับ แต่ถ้าตารางที่ไม่มี column shape ก็จะไม่ error ครับ
code ที่ผมใช้ดังนี้ครับ vb.net(2005)

Dim SQL As String = "Select * from " & ComboBox.Text
Dim dts As DataTable = connectAcc(SQL).Tables(0)
DGView.DataSource = dts

อันนี้เป็น module ติดต่อฐานข้อมูลของผม

Code (VB.NET)
Imports System.Data
Imports System.Data.OleDb
Module connectDatabase
    Public conStr As String = "Provider=Microsoft.JET.OLEDB.4.0;data source=" & filePatch & ";"
    Public conn As OleDbConnection = New OleDbConnection(conStr)

    Public Sub openConnection()
        If conn.State = ConnectionState.Closed Then
            conn.Open()
        End If
    End Sub
    Public Function connectAcc(ByVal command As String) As DataSet
        Dim a As New DataSet
        a.Tables.Add(0)
        Try
            Dim da As OleDbDataAdapter = New OleDbDataAdapter(command, conn)
            a.Tables.Clear()
            da.Fill(a)
        Catch ex As Exception
            MessageBox.Show("Error" & ex.Message)
            a.Tables.Clear()
            a.Tables.Add(0)
            Return a
        End Try
        Return a
    End Function

End Module




Tag : - - - -







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2009-11-12 13:35:03 By : phisin View : 1639 Reply : 2
 

 

No. 1

Guest


ลองดูครับ Ex. c# ดูไฟล์

Preview binary data store in sql server to cilent browser by Gridview
1. Set up Gridview in html tax.

Code (C#)
                                                    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" OldValuesParameterFormatString="original_{0}"
                                                                SelectMethod="GetDataSrh" 
                                                                TypeName="superbo.ksn.Data.KsnFileTableAdapters.KsnFileSrhTableAdapter" 
                                                                EnablePaging="True" MaximumRowsParameterName="MaxRows" 
                                                                SelectCountMethod="MaxRowsSrh" StartRowIndexParameterName="RowIndex">
                                                            </asp:ObjectDataSource>
                                                            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" 
                                                                CssClass="table_edit" DataSourceID="ObjectDataSource1"
                                                                EnableModelValidation="True" ForeColor="#333333" GridLines="None" 
                                                                AllowPaging="True" OnRowCommand="GridView1_RowCommand" 
                                                                OnRowDataBound="GridView1_RowDataBound" 
                                                                onselectedindexchanged="GridView1_SelectedIndexChanged" 
                                                                EnableSortingAndPagingCallbacks="True" Caption="จำนวนข้อมูล 0 รายการ" 
                                                                CaptionAlign="Right">
                                                                <AlternatingRowStyle BackColor="#E6ECF7" />
                                                                <EditRowStyle BackColor="#BECFEB" />
                                                                <FooterStyle BackColor="#3366CC" Font-Bold="True" ForeColor="White" 
                                                                    HorizontalAlign="Left" />
                                                                <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                                                                <PagerSettings Mode="NumericFirstLast" 
                                                                    FirstPageImageUrl="~/images/34all2/tostart.png" 
                                                                    LastPageImageUrl="~/images/34all2/toend.png" 
                                                                    NextPageImageUrl="~/images/34all2/foward.png" 
                                                                    PreviousPageImageUrl="~/images/34all2/backward.png" />
                                                                <PagerStyle BackColor="White" ForeColor="#3366CC" HorizontalAlign="Center" />
                                                                <RowStyle BackColor="#EFF3FB" VerticalAlign="Top" />
                                                                <SelectedRowStyle BackColor="#B3C7E8" Font-Bold="True" ForeColor="#333333" />
                                                                <Columns>
                                                                    <asp:BoundField DataField="Id_KsnFile" HeaderText="ID" InsertVisible="False" 
                                                                        ReadOnly="True" SortExpression="Id_KsnFile">
                                                                    <ItemStyle Width="60px" />
                                                                    </asp:BoundField>
                                                                    <asp:BoundField DataField="Id_GroupFile" HeaderText="ลำดับกลุ่ม" 
                                                                        SortExpression="Id_GroupFile" ReadOnly="True">
                                                                    <ItemStyle Width="60px" />
                                                                    </asp:BoundField>
                                                                    <asp:BoundField DataField="GroupName" HeaderText="กลุ่ม" 
                                                                        SortExpression="GroupName" ReadOnly="True" >
                                                                    <ItemStyle Width="250px" />
                                                                    </asp:BoundField>
                                                                    <asp:TemplateField HeaderText="ภาพแสดง" ShowHeader="False">
                                                                        <ItemTemplate>
                                                                            <asp:ImageButton ID="ibtnView" runat="server" CssClass="ImageBox1" CausesValidation="False" 
                                                                                CommandName="View" ImageUrl="" 
                                                                                ToolTip="ภาพ" />
                                                                        </ItemTemplate>
                                                                        <ItemStyle HorizontalAlign="Center" />
                                                                        <HeaderStyle HorizontalAlign="Center" />
                                                                    </asp:TemplateField>
                                                                    <asp:TemplateField HeaderText="" ShowHeader="False">
                                                                        <ItemTemplate>
                                                                            <asp:ImageButton ID="ibtnEdit" runat="server" CausesValidation="False" 
                                                                                CommandName="Edit" ImageUrl="~/images/Function_Icon_Set/paper_content_pencil_48.png" 
                                                                                ToolTip="แก้ไขข้อมูลรายการนี้" />
                                                                        </ItemTemplate>
                                                                        <ItemStyle HorizontalAlign="Center" />
                                                                        <HeaderStyle HorizontalAlign="Center" />
                                                                    </asp:TemplateField>
                                                                </Columns>
                                                            </asp:GridView>


Interface as


2. Create code in event that fix in Gridview (hidden code or exist script runat server)

Code (C#)
      protected void GridView1_RowDataBound(Object sender, GridViewRowEventArgs e)
        {
            if (!String.IsNullOrEmpty(e.Row.Cells[0].Text))
            {
                ImageButton ibtnView = (ImageButton)e.Row.FindControl("ibtnView");
                if (ibtnView != null)
                {
                    ibtnView.CommandArgument = e.Row.Cells[0].Text;
                    ibtnView.ImageUrl = "../Shared/LoadContent.aspx?fz=ksnfile&fid=" + e.Row.Cells[0].Text;
                    ibtnView.OnClientClick = "window.open('../Shared/LoadContent.aspx?fz=ksnfile&fid=" + e.Row.Cells[0].Text + "');";
                }
                ImageButton ibtnEdit = (ImageButton)e.Row.FindControl("ibtnEdit");
                if (ibtnEdit != null)
                {
                    ibtnEdit.CommandArgument = e.Row.Cells[0].Text;
                }
                //ImageButton ibtnDelete = (ImageButton)e.Row.FindControl("ibtnDelete");
                //if (ibtnDelete != null)
                //{
                //    ibtnDelete.CommandArgument = e.Row.Cells[0].Text;
                //}
            }
        }


3. LoadContent.aspx is blank page that have code this

Code (C#)
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                if (!String.IsNullOrEmpty(this.Request.QueryString["fz"]))
                {
                    bool havefile = false; 
                    //ksnfile (TKsnFile)
                    if (this.Request.QueryString["fz"].ToString() == "ksnfile")
                    {
                        if (!String.IsNullOrEmpty(this.Request.QueryString["fid"]))
                        {
                            int fileID = Convert.ToInt32(this.Request.QueryString["fid"].ToString());
                            superbo.ksn.Data.KsnFileTableAdapters.TKsnFileTableAdapter da = new superbo.ksn.Data.KsnFileTableAdapters.TKsnFileTableAdapter();
                            superbo.ksn.Data.KsnFile.TKsnFileDataTable dt = da.GetFileByPK(fileID);
                            if (dt != null)
                            {
                                foreach (superbo.ksn.Data.KsnFile.TKsnFileRow dr in dt.Rows)
                                {
                                    Response.BinaryWrite(dr.FileObject);
                                    havefile = true;
                                }
                            }
                            dt.Dispose();
                            da.Dispose();
                        }
                    }


                }
            }
        }


4. Try it.






Date : 2009-11-18 23:37:00 By : bo
 


 

No. 2



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

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

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

Code (C#)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace ASPNetBLOB
{
    public partial class ViewImg : System.Web.UI.Page
    {
        SqlConnection objConn = new SqlConnection();
        SqlCommand objCmd;
        string strConnString;
        string strSQL;

        protected void Page_Load(object sender, EventArgs e)
        {
            strConnString = "Server=localhost;Uid=sa;PASSWORD=;database=mydatabase;Max Pool Size=400;Connect Timeout=600;";
            objConn.ConnectionString = strConnString;
            objConn.Open();

            //*** DataTable ***'
            SqlDataAdapter dtAdapter = default(SqlDataAdapter);
            DataTable dt = new DataTable();
            strSQL = "SELECT * FROM files WHERE FilesID = @sFilesID ";
            dtAdapter = new SqlDataAdapter(strSQL, objConn);
            objCmd = dtAdapter.SelectCommand;
            objCmd.Parameters.Add("@sFilesID", SqlDbType.Int).Value = Request.QueryString["FilesID"].ToString();
            dtAdapter.Fill(dt);

            if (dt.Rows.Count > 0)
            {
                Response.ContentType = dt.Rows[0]["FilesType"].ToString();
                Response.BinaryWrite((byte[])dt.Rows[0]["FilesName"]);
            }

            dt = null;
        }

        protected void Page_Unload(object sender, System.EventArgs e)
        {
            objConn.Close();
            objConn = null;
        }
    }
}


Go to : (C#) ASP.NET SQL Server BLOB Binary Data and Parameterized Query
Date : 2011-06-02 18:15:52 By : webmaster
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : .NET + SQL Server พี่ครับผมช่วยดู Error ของข้อมูล long binary data ที่แสดงใน DataGridView หน่อยครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 03
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 อัตราราคา คลิกที่นี่