PDA

Click to See Complete Forum and Search --> : Datagrid On the Fly


mahivr
Oct 20th, 2004, 01:50 AM
i have a sql query

select A.topcol,B.fstcol from table1 A,table2 B.....

im trying to contruct a datagrid with title column from one table and 1st column from another table record


how to implement this datagrid on the fly
or is any other way to contruct this with Table object?

v.r.mahendran

indydavid32
Oct 20th, 2004, 03:05 PM
Mahivr, this is what I did. If you use your select statement like this... Select Vendor_ID as [Vendor ID]... Then the column header will be Vendor ID. Here is an example.Dim cn As New OleDb.OleDbConnection("Provider=SQLOLEDB.1;Integrated Security=SSPI;" _
& "Persist Security Info=False;" _
& "Initial Catalog=fuel info;" _
& "UID=;PWD=;" _
& "Data Source=Server7")
cn.Open()

Dim datAdapt As New OleDb.OleDbDataAdapter("Select Vendor_No as [Vendor No], " & _
"Vendor_Name as [Vendor Name], Vendor_Terminal as [Vendor Terminal], " & _
"Vendor_Trmnl_No As [Terminal No], Vendor_City As [City], Vendor_State As " & _
"[State], ID From Other_Vendors Order By Vendor_Name", cn)

Dim datSet As New Data.DataSet

datAdapt.Fill(datSet, "Other_Vendors")

DataGrid1.DataSource = datSet
DataGrid1.DataKeyField = "ID"
DataGrid1.DataBind()