如何在数据网格视图中查看表 [英] how to view table in data grid view

查看:76
本文介绍了如何在数据网格视图中查看表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在不使用适配器的情况下使用数据网格视图查看表....请告诉我

how to view the table using data grid view without adapter using..... pls tell me

推荐答案



数据集实际上是一个您可以通过代码自行操作的类.它使用其他类,例如数据表,数据行等...如果您查看DataGrid.DataSource属性上的MSDN库,您将看到一个示例,该示例说明如何用数据视图填充数据源,完全由代码组成.另外,请务必检查出DataSet类和DataTable类.

Hi,

a dataset is actually a class that you can manipulate on your own through code. It uses other classes like datatables, datarows, ... If you take a look at the MSDN library on the DataGrid.DataSource property, you''ll see an example on how the datasource get''s filled with a dataview that''s entirely made up with code. Also be sure to check out the DataSet class and the DataTable class.

Imports System.Data.SqlClient

Imports System.Configuration.ConfigurationSettings

Public Class test1

Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

''This call is required by the Web Form Designer.

<system.diagnostics.debuggerstepthrough()> Private Sub InitializeComponent()

End Sub

Protected WithEvents dgProduct As System.Web.UI.WebControls.DataGrid

''NOTE: The following placeholder declaration is required by the Web Form Designer.

''Do not delete or move it.

Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init

''CODEGEN: This method call is required by the Web Form Designer

''Do not modify it using the code editor.

InitializeComponent()

End Sub

#End Region

Dim con As String = AppSettings("ConnectionString")

Dim objSQLCon As New SqlConnection(con)

Dim cmd As SqlCommand

Dim red As SqlDataReader

Function CreateDataSource() As ICollection

Dim dt As New DataTable

Dim dr As DataRow

dt.Columns.Add(New DataColumn("Product Code", GetType(String)))

dt.Columns.Add(New DataColumn("Product Description", GetType(String)))

dt.Columns.Add(New DataColumn("Product Availability", GetType(String)))

Dim queryCode As String = "Select Prod_Code,Prod_Description,Prod_Availability from Product"

Dim objCmdCode As New SqlCommand(queryCode, objSQLCon)

Dim rdrCode As SqlDataReader

Dim row As DataRow

objSQLCon.Open()

rdrCode = objCmdCode.ExecuteReader

Do While rdrCode.Read

row = dt.NewRow()

row(0) = rdrCode.GetValue(0)

row(1) = rdrCode.GetValue(1)

row(2) = rdrCode.GetValue(2)

dt.Rows.Add(row)

Loop

objSQLCon.Close()

Dim dv As New DataView(dt)

Return dv

End Function ''CreateDataSource

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

''Put user code to initialize the page here

If Not IsPostBack Then

'' Load this data only once.

dgProduct.DataSource = CreateDataSource()

dgProduct.DataBind()

End If

End Sub

End Class
<form id="frmTest" method="post" runat="server">
   <asp:datagrid id="dgProduct" runat="server" width="400px" height="128px" autogeneratecolumns="true" xmlns:asp="#unknown">
    
   </asp:datagrid>
  </form>


这篇关于如何在数据网格视图中查看表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆