The reson i am asking for the datagrid is becasue i have a code written to read a data using datareader and display it in dagagrid. It was easy to do that and i just got a new vs 2005 and I do not really know how to convert the code to work in gridview. I wonder if gridview supports executeReader() method to populate a datareader?
Many thanks to all
<Script runat="server" language="VB">
Dim myConnection as OleDbConnection
Dim dr as OleDbDataReader
Dim cmd as OleDbCommand
Dim connectionString as string
Dim i As Integer
Dim filename as string
Dim sb as System.Text.StringBuilder
Dim myConnectionc as OleDbConnection
Dim drc as OleDbDataReader
Dim cmdc as OleDbCommand
Dim connectionStringc as string
Dim StrSql as string
Sub page_load()
lblTime.Text =DateTime.Now.ToString()
connectionString = "provider=MSDAORA;Data Source=tplp;User ID=tplcp;Password=tplcp;"
myConnection = new OleDbConnection(connectionString)
myConnection.Open()
StrSql= "SELECT (substr( ITEM ,1,4)||'.'||substr(item,5)) Item_Number, IDESCR Short_Description, IDESCRL Long_Description, IUNITS Unit_Name," Plan_Unit_Description " & _
"FROM ITEMLIST " & _
" WHERE ISPECYR='00' AND IOBSELET='N' and ITEM <> '2999509/00001' "
cmd = New OleDbCommand(StrSql,myConnection)
dr = cmd.ExecuteReader()
dgMetric.DataSource =dr
dgMetric.DataBind()
connectionStringc = "provider=MSDAORA;Data Source=tplp;User ID=tplcp;Password=tplcp;"
myConnectionc = new OleDbConnection(connectionStringc)
myConnectionc.Open()
filename = "EnglishItemList.csv"
cmdc = New OleDbCommand(StrSql,myConnectionc)
drc = cmdc.ExecuteReader()
sb = New System.Text.StringBuilder
End sub
Sub Click(ByVal sender as System.Object, ByVal e as System.EventArgs)
'for field name
For i=0 to drc.FieldCount-1
If i < (drc.FieldCount-1) then
sb.Append(Chr(34)&drc.GetName(i)&Chr(34)&",")
Else
sb.Append(Chr(34)&drc.GetName(i)&Chr(34)& VbCrLf)
End If
Next
'for field value
While drc.Read()
For i=0 to drc.FieldCount-1
If i < (drc.FieldCount-1) then
sb.Append(Chr(34) & drc.GetValue(i).ToString.Replace(Chr(34),Chr(34) & Chr(34)) & Chr(34) & ",")
'sb.Append(Chr(34)&drc.GetValue(i).ToString & Chr(34)&",")
Else
sb.Append(Chr(34)&drc.GetValue(i).ToString & Chr(34)& VbCrLf)
End if
Next
End while
drc.close()
myConnectionc.Close()
Response.ContentType ="Application/x-csv"
Response.AddHeader("content-disposition","attachment;filename="""& filename &"""")
Response.Write(sb.ToString)
Response.End()
End Sub
</Script>