|
 |
aspx thread: Fill datagrid from dataset
Message #1 by =?iso-8859-1?Q?Gon=E7alo_Borr=EAga?= <goncalo.borrega@i...> on Thu, 19 Sep 2002 09:51:10 +0100
|
|
Hello,
I have 2 tables, Contact & ContactType.
Contact has a foreign key (ContactTypeID) to ContactType.
I have filled a dataset with both 2 tables and created the relation
between them.
What I would like to do is fill a datagrid (aspx) with the info from the
join.
Ex. Contact.ContactID | ContactType.Description |
Contact.Description
Is there any way I can do that without creating a view in the database
or getting the join from the StoreProc? Only by using the dataset...
TIA
Gon=E7alo Borr=EAga
Message #2 by chunges@h... on Wed, 25 Sep 2002 06:12:42
|
|
Hi, Before you are using you need DataAdapter object to connect Command
object to a DataSet object.
When you configure the DataAdapter, then the wizard will guide you whether
you want to use Query Statement , existing Stored Procedure or new Stored
Procedure. If you don't want to use Store Proc you can write your own
Query Statement to join your Contact & ContactType tables.
Then you can fill your dataset.Eg.
DataAdapter.Fill(DataSet)
Let Say you use data grid(DataGrid1) to display it, then :
DataGrid1.Databind()
DataGrid1.visible = true
Hope this is helpful.
Cheers, Eng Sim
(Malaysia)
> Hello,
I have 2 tables, Contact & ContactType.
Contact has a foreign key (ContactTypeID) to ContactType.
I have filled a dataset with both 2 tables and created the relation
between them.
What I would like to do is fill a datagrid (aspx) with the info from the
join.
Ex. Contact.ContactID | ContactType.Description |
Contact.Description
Is there any way I can do that without creating a view in the database
or getting the join from the StoreProc? Only by using the dataset...
TIA
Gon=E7alo Borr=EAga
Message #3 by ramprasad upadhyaya <rpu_forum@y...> on Tue, 24 Sep 2002 22:41:49 -0700 (PDT)
|
|
Hi,
Refer below code to do so....
Function fncGetPurchaseOrder(ByVal strUsrId As String, ByVal strPONo As String, ByVal strFromDate As String, ByVal strToDate As
String, ByVal strSortField As Object, ByVal strSortDir As Object) As DataSet
InitializeConnectionAxdb()
strSQL = "SELECT " & _
" PURCHORDERFORMNUM,CREATEDDATE,SALESNAME,'SALESSTATUS'= CASE WHEN SALESSTATUS = 0 THEN 'None' WHEN SALESSTATUS = 1 THEN 'Open
Order' WHEN SALESSTATUS = 2 THEN 'Shipped' WHEN SALESSTATUS = 3 THEN 'Invoiced' WHEN SALESSTATUS = 4 then 'Canceled' END,SALESTAKER,
" & _
" DELIVERYADDRESS, DELIVERYDATE,ltrim(SALESID) AS 'SALESID',CUSTACCOUNT,DELIVERYCOUNTRY,DELIVERYZIPCODE,DELIVERYSTATE,DELIVERYCOUNTY
" & _
" FROM " & _
" SalesTable(NOLOCK) " & _
" WHERE " & _
" CUSTACCOUNT ='" & strUsrId & "'"
If Trim(strPONo) <> "-1" Then
strSQL = strSQL & " AND PURCHORDERFORMNUM ='" & Replace(strPONo, "'", "''") & "'"
Else
If Trim(strToDate) = "" Then
strToDate = "GETDATE()"
strSQL = strSQL & " AND CREATEDDATE BETWEEN '" & strFromDate & "' AND " & strToDate & " "
Else
strSQL = strSQL & " AND CREATEDDATE BETWEEN '" & strFromDate & "' AND '" & strToDate & "' "
End If
End If
If strSortField Is Nothing Then
strSQL = strSQL & " ORDER BY CREATEDDATE DESC "
Else
strSQL = strSQL & " ORDER BY " & strSortField & " " & strSortDir
End If
'ADDED BY RAMPRASAD.S.U FOR ADDING S.NO FOR GRID ON 18-SEP-2002
'--------------------------------------------------------------
Dim dclmn As New DataColumn("S.No")
dclmn.AutoIncrement = True
dclmn.AutoIncrementSeed = 1
dclmn.AutoIncrementStep = 1
'END
'--------------------------------------------------------------
daNex = New SqlDataAdapter(strSQL, conNex)
'ADDED BY RAMPRASAD.S.U FOR ADDING S.NO FOR GRID ON 18-SEP-2002
'--------------------------------------------------------------
Dim dtbl As New DataTable("SalesTable")
dtbl.Columns.Add(dclmn)
dsPO.Tables.Add(dtbl)
'--------------------------------------------------------------
daNex.Fill(dsPO, "SalesTable")
datagrid.datasource=dsPO
datagrid.databind()
end function
Regards
Ramprasad. Upadhyaya
chunges@h... wrote:Hi, Before you are using you need DataAdapter object to connect Command
object to a DataSet object.
When you configure the DataAdapter, then the wizard will guide you whether
you want to use Query Statement , existing Stored Procedure or new Stored
Procedure. If you don't want to use Store Proc you can write your own
Query Statement to join your Contact & ContactType tables.
Then you can fill your dataset.Eg.
DataAdapter.Fill(DataSet)
Let Say you use data grid(DataGrid1) to display it, then :
DataGrid1.Databind()
DataGrid1.visible = true
Hope this is helpful.
Cheers, Eng Sim
(Malaysia)
> Hello,
I have 2 tables, Contact & ContactType.
Contact has a foreign key (ContactTypeID) to ContactType.
I have filled a dataset with both 2 tables and created the relation
between them.
What I would like to do is fill a datagrid (aspx) with the info from the
join.
Ex. Contact.ContactID | ContactType.Description |
Contact.Description
Is there any way I can do that without creating a view in the database
or getting the join from the StoreProc? Only by using the dataset...
TIA
Gon=E7alo Borr=EAga
---
ASP.NET 1.0 Namespace Reference with C#
http://www.wrox.com/acon11.asp?ISBN=1861007442
ASP.NET 1.0 Namespace Reference with VB.NET
http://www.wrox.com/acon11.asp?ISBN=1861007450
These books are a complete reference to the ASP.NET namespaces
for developers who are already familiar with using ASP.NET.
There is no trivial introductory material or useless .NET
hype and the presentation of the namespaces, in an easy-to use
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes,
giving you those real-world tips that the documentation doesn't
offer, and demonstrating complex techniques with simple
examples.
---
---------------------------------
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
|
|
 |