|
public static string WriteCSVFilebyDataReader(SqlDataReader SqlDataReaderObject)
{
StringBuilder strResult = new StringBuilder();
try
{
for (int i = 0; i < SqlDataReaderObject.FieldCount; i++)
{
strResult.Append("\" " + SqlDataReaderObject.GetName(i) + " \",");
}
strResult.Append("\n");
if (SqlDataReaderObject.HasRows)
{
while (SqlDataReaderObject.Read())
{
for (int j = 0; j < SqlDataReaderObject.FieldCount; j++)
{
strResult.Append("\"" +SqlDataReaderObject.GetValue(j).ToString() + "\",");
}
strResult.Append("\n");
//SqlDataReaderObject.NextResult();
}
}
}
catch (Exception ex)
{
throw ex;
}
return strResult.ToString();
}
|
|
|
|
|
When you use a datareader, data is not fetched from the database until you use the Read() method to read the next row, therefore you may not receive an error when you open the datareader. The problem seems to be with StringBuilder. You can split the result into batches of say 10000 rows and then write them. For example, open the csv file write 10000 rows, close it, then append the next 10000 rows and so on. You could do this using a loop counter. Each batch would use a new StringBuilder instance to write to the csv file.
|
|
|
|
|
Hi everyone,
Please read the xml file below. Thanks.
(1). Given id="100" and quantity=2. id="100" exists in the xml file. Then update quantity (i.e., 1+2 = 3) in the xml file.
(2). Given id="300" and quantity=1. id="300" does not exist in the xml file,
then insert this new record (i.e., <item id="300"><itemName>Bike</itemName><price>150.99</price><quantity>1</quantity></item>)
into the xml file.
(3). Given id="200". id="200" exist, then delete this record (<item id="200"><itemName>Car</itemName><price>99.99</price><quantity>1</quantity></item>)
<products>
<item id="100">
<itemName>Car</itemName>
<price>99.99</price>
<quantity>1<quantity>
</item>
<item id="200">
<itemName>Car</itemName>>
<price>99.99</price>
<quantity>1</quantity>
</item>
</products>
iam writing code in vb.net but i cont
please help me,
Can I have some sample code
Thanks,
modified on Tuesday, November 3, 2009 9:26 AM
|
|
|
|
|
|
|
pramodgorityala wrote: Can I have some sample code
Let's save you some time and trouble. Give us the email address of your teacher and we'll send the solution direct to him.
|
|
|
|
|
Welcome to the ASP.NET forum....
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Hi all,
I have an asp.net page ,contains 3 textboxes ,1 dropdownlis,1 button.
I have written the code for inserting data to the database inn the button click event.Its working properly,and cleared the textbox datas.
But after inserting the datas, I clear the texts in the textboxes and set visible=false.
Afetr this I tried to refresh the page,the above textbox values are again inserted into the database.
If somebody knows about this ,pls help me.
Thanks and Regards
Denny
|
|
|
|
|
TextBox.Text=""; to clear data in text box...
|
|
|
|
|
I have done already but still prob
|
|
|
|
|
The postback data won't be cleared and when you refresh, it will be resend. To work around this, consider redirecting the page after insert.
Response.Redirect("success.aspx")
Best wishes,
Navaneeth
|
|
|
|
|
but sir,i have a grid in that page and i want to show the values in the grid
|
|
|
|
|
This is the way ASP.NET postback works. When you refresh, your browser submits the same page with the same postback information. The only way you can avoid it is by redirecting it to a different page.
|
|
|
|
|
|
What do you mean when you say 'refresh the page?' How, exactly, are you doing that?
Ignore any answers that suggest that viewstate will not contain the latest value inserted into a textbox, including string.empty.
Without seeing rhe code it's hard to know, but it sounds like you may be rebinding those textboxes to your datastore.
|
|
|
|
|
What is the best approach to persist a dataset across postbacks so that users could manipulate the data in it and could be saved(to the database) at last.
|
|
|
|
|
You can put it in ViewState .
Best wishes,
Navaneeth
|
|
|
|
|
I am using ViewState now but I notice the page is slower during reloads
|
|
|
|
|
You can use viewstate, but if the size of the dataset is very large, it will bloat the request and response size and can probably kill your app. Use a DataTable object and persist it in session. You can also try serializing the object to a database and save the key in viewstate. Each approach has its own advantages and disadvantages. You should try to find out what works best for you.
|
|
|
|
|
Hello Shameel
How about persisting the DataSet(as I have more than one DataTable) in a Session variable and clearing it(using Session.Remove()) while the user navigates away from the page?
|
|
|
|
|
The best way is not to Persist the dataset ever. Just save the changes during postbacks and show the most recent data.
Remember, the user might go next page on next date. Or might be there is a session timeout. If you store everything in context, that means errors might loose everything.
|
|
|
|
|
Thank you Abhishek
You re right. But here I am faced with a situation to reduce database hits rather than concurrency. I am having multiple tables so using DataSet. When I stored it in a ViewState variable I notice the page loading slower.
|
|
|
|
|
Dont load such a huge data in ViewState.
When you request for something, you send viewstate with it(even if it is an AJAX request). After receiving the viewstate it decrypts it using Machine key. It then modifies the viewstate according to your serverside program and then finally encrypts it... converts the encrypted string to Base64 and written over Response stream.
That means for every request this huge amount of task IIS has to perform. Hence slow output.
We generally place EnableViewState = false for frequently visited pages to have better performance. So according to me writing a Dataset(which serializes it and write to page) is not good.
On the other hand, Server memory is very low. If there are lots of connections, there might be a huge possibility to have Session OutofMemory. But if you dont have concurrent connections, you might use Session. But dont put the dataset, as there are a lots of properties which are not required. Rather make a list of DataRows and place them in session(Improves than writing DataSet). But still, I dont like this as well.
If I was there, I will always compromise Database hits than Server memory.
|
|
|
|
|
Hi All,
In my project using Ajax controls that is update panel,Modal controls and VS 2008, i am getting the Error in Log Database.But application running very fine.Why this Exception is generated?The Application is in Live....
HandlingInstanceID: 0c17cc24-7940-4807-a07e-e92170031d69 An exception of type 'System.Web.HttpException' occurred and was caught. ------------------------------------------------------------------------ 11/01/2009 04:03:55 Type : System.Web.HttpException, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a Message : The file '/4L5rpd4F.asmx' does not exist. Source : System.Web Help link : ErrorCode : -2147467259 Data : System.Collections.ListDictionaryInternal TargetSite : Void CheckVirtualFileExists(System.Web.VirtualPath) Stack Trace : at System.Web.UI.Util.CheckVirtualFileExists(VirtualPath virtualPath) at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) at System.Web.Compilation.BuildManager.GetVPathBuildResult(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) at System.Web.Compilation.BuildManager.GetVPathBuildResult(HttpContext context, VirtualPath virtualPath) at System.Web.UI.WebServiceParser.GetCompiledType(String inputFile, HttpContext context) at System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String
Please giving me any suggestion, by that i can resolve the problem..
Thanks in Advance.
JohnDas
|
|
|
|
|
I think this is FileNotFound Exception.
The file '/4L5rpd4F.asmx' does not exist
|
|
|
|