本文介绍了GridView订单页面购物车页面ASP.NET SQL-无法查看数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI,
我想从数据库中获取数据并将其显示在DataGrid中.我使用自动生成的列false和"PictureURL"是图像字段,但这给出了空的DataGrid.



I would like to take data from database and show it in DataGrid. I used auto generated columns false and "PictureURL" is image field, but this gives empty DataGrid.


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim Con As New SqlConnection(ConfigurationManager.AppSettings("ConnectionString").ToString())
        Con.Open()
        Dim Sel As String = "Select * from Item"
        Dim cmd As New SqlCommand(Sel, Con)

        Dim dt As New DataTable()
        dt.Columns.Add(New DataColumn("PictureID", GetType(Integer)))
        dt.Columns.Add(New DataColumn("PictureURL", GetType(String)))
        dt.Columns.Add(New DataColumn("Title"", GetType(String)))
        dt.Columns.Add(New DataColumn("DateAdded";, GetType(DateTime)))
        dt.Columns.Add(New DataColumn("Price"", GetType(Decimal)))
        Dim reader As SqlDataReader = cmd.ExecuteReader()
        While reader.Read()
            Dim dr As DataRow = dt.NewRow()
            dr("PictureID") = Convert.ToInt32(reader("PictureID"))
            dr("PictureURL") = ResolveUrl("~/images/" + reader("PictureURL"))
            dr("Title") = reader("Title")
            dr("DateAdded") = reader("DateAdded")
            dr("Price") = reader("Price")
            dt.Rows.Add(dr)
        End While
        Con.Close()
         GridView1.DataSource = dt
        GridView1.DataMember = "Item"
        GridView1.DataBind()


    End Sub

推荐答案


这篇关于GridView订单页面购物车页面ASP.NET SQL-无法查看数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 05:38