Hi
I have a created a simple ASP page that return a row of 7K records using a data grid control and created a link for whomever to download the code as a CSV file. Everything works fine but for the result to be displayed on the data grid control is slow and it takes a lot longer to open a link for a CSV file. I am just guessing there is something inside the code that slows the whole process.
My question is:
1-Can I use one connection string and use it with two different objects.
2-Can I use one sql statement for both CSV file link and display the record in a data grid control.
3-Can I combine the code I use to create a CSV file with data grid and still get the CSV file and display the record in a data grid control.I really apprecite if someone could take a look at and give me an advise where to make the correction.
Below is the code :
Thanks
<Html>
<Head>
<Title>connecting to a database using VB</Title>
<style type="text/css">
<!--
.style4 {
font-size: 24px;
font-weight: bold;
}
-->
</style>
</Head>
<%@ Page Trace="False" Debug="True" Language="VB" %>
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.OleDb"%>
<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
Sub page_load()
connectionString = "provider=MSDAORA;Data Source=xx;User ID=yy;Password=yy;"
myConnection = new OleDbConnection(connectionString)
myConnection.Open()
cmd = New OleDbCommand("SELECT (substr( ITEM ,1,4)||'.'||substr(item,5)) as Item , IDESCR ,IDESCRL ,IUNITS FROM ITEMLIST WHERE ISPECYR='01' and IOBSELET = 'N' and ITEM <> '2999509/00001 ' ",myConnection)
dr = cmd.ExecuteReader()
dgMetric.DataSource =dr
dgMetric.DataBind()
connectionString = "provider=MSDAORA;Data Source=xx;User ID=yy;Password=yy;"
myConnectionc = new OleDbConnection(connectionStringc)
myConnectionc.Open()
filename = "MetricItemList.csv"
cmdc = New OleDbCommand("SELECT (substr( ITEM ,1,4)||'.'||substr(item,5))as Item_Number, IDESCR as Short_Description, IDESCRL as Long_Description, IUNITS as Unit FROM ITEMLIST WHERE ISPECYR='01' and IOBSELET = 'N' and ITEM <> '2999509/00001 ' ",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 & 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>
<Body>
<table width="100%" border="0" >
<form runat="server">
<div align="center"><span class="style4">Bid Letting </span><br>
Trns*port Item Lists (Metric System -This list went into effect with the 2000 Spec. Book)
</div>
<P align="right"> Metric system item list data below as:
<asp:LinkButton id="btnSubmit" runat="Server" text=" Comma-Separated Values" OnClick="Click"/>
</P>
<hr>
<aspataGrid id="dgMetric" runat="server" autoGenerateColumns="false" cellpadding="4" width="100%">
<ItemStyle Font-Name="Arial" Font-Size="9pt" ForeColor="#000000"/>
<HeaderStyle Font-Name="Arial" Font-Size="9pt" Font-Bold="true" BackColor ="#003366" ForeColor ="#FFFFFF"/>
<AlternatingItemStyle Font-Name ="Arial" Font-Size ="9pt" BackColor ="#CCCCCC"/>
<columns>
<asp:boundColumn DataField="Item" HeaderText="Item Number"/>
<asp:boundColumn DataField="IDescr" HeaderText="Short Description"/>
<asp:boundColumn DataField="IDescrl" HeaderText="Long Description"/>
<asp:boundColumn DataField="Iunits" HeaderText="Unit Name"/>
</columns>
</aspataGrid>
</form>
</table>
</Body>
</Html>
I have a created a simple ASP page that return a row of 7K records using a data grid control and created a link for whomever to download the code as a CSV file. Everything works fine but for the result to be displayed on the data grid control is slow and it takes a lot longer to open a link for a CSV file. I am just guessing there is something inside the code that slows the whole process.
My question is:
1-Can I use one connection string and use it with two different objects.
2-Can I use one sql statement for both CSV file link and display the record in a data grid control.
3-Can I combine the code I use to create a CSV file with data grid and still get the CSV file and display the record in a data grid control.I really apprecite if someone could take a look at and give me an advise where to make the correction.
Below is the code :
Thanks
<Html>
<Head>
<Title>connecting to a database using VB</Title>
<style type="text/css">
<!--
.style4 {
font-size: 24px;
font-weight: bold;
}
-->
</style>
</Head>
<%@ Page Trace="False" Debug="True" Language="VB" %>
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.OleDb"%>
<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
Sub page_load()
connectionString = "provider=MSDAORA;Data Source=xx;User ID=yy;Password=yy;"
myConnection = new OleDbConnection(connectionString)
myConnection.Open()
cmd = New OleDbCommand("SELECT (substr( ITEM ,1,4)||'.'||substr(item,5)) as Item , IDESCR ,IDESCRL ,IUNITS FROM ITEMLIST WHERE ISPECYR='01' and IOBSELET = 'N' and ITEM <> '2999509/00001 ' ",myConnection)
dr = cmd.ExecuteReader()
dgMetric.DataSource =dr
dgMetric.DataBind()
connectionString = "provider=MSDAORA;Data Source=xx;User ID=yy;Password=yy;"
myConnectionc = new OleDbConnection(connectionStringc)
myConnectionc.Open()
filename = "MetricItemList.csv"
cmdc = New OleDbCommand("SELECT (substr( ITEM ,1,4)||'.'||substr(item,5))as Item_Number, IDESCR as Short_Description, IDESCRL as Long_Description, IUNITS as Unit FROM ITEMLIST WHERE ISPECYR='01' and IOBSELET = 'N' and ITEM <> '2999509/00001 ' ",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 & 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>
<Body>
<table width="100%" border="0" >
<form runat="server">
<div align="center"><span class="style4">Bid Letting </span><br>
Trns*port Item Lists (Metric System -This list went into effect with the 2000 Spec. Book)
</div>
<P align="right"> Metric system item list data below as:
<asp:LinkButton id="btnSubmit" runat="Server" text=" Comma-Separated Values" OnClick="Click"/>
</P>
<hr>
<aspataGrid id="dgMetric" runat="server" autoGenerateColumns="false" cellpadding="4" width="100%">
<ItemStyle Font-Name="Arial" Font-Size="9pt" ForeColor="#000000"/>
<HeaderStyle Font-Name="Arial" Font-Size="9pt" Font-Bold="true" BackColor ="#003366" ForeColor ="#FFFFFF"/>
<AlternatingItemStyle Font-Name ="Arial" Font-Size ="9pt" BackColor ="#CCCCCC"/>
<columns>
<asp:boundColumn DataField="Item" HeaderText="Item Number"/>
<asp:boundColumn DataField="IDescr" HeaderText="Short Description"/>
<asp:boundColumn DataField="IDescrl" HeaderText="Long Description"/>
<asp:boundColumn DataField="Iunits" HeaderText="Unit Name"/>
</columns>
</aspataGrid>
</form>
</table>
</Body>
</Html>