|
I think it is implemented using the CodeDOM. Visual Studio will be calling a custom code generator for inserting that snippet of code. Can't find it though. Found the stuff for generating the default constuctor code, typed datasets, and all sorts by using reflector, but not Dispose. Must be hidden away in the bowels of the framework.
A good article on using the CodeDOM can be found here[^]
|
|
|
|
|
Thanks!
--
"Keyboard not found. Press < F1 > to RESUME. "
Source unknown (appears in many common BIOSes as a real error message)
|
|
|
|
|
Hey,
I'm creating a .Net download library. Part of the reason I'm doing this is to learn more about mulithreading. I've run into some things now that I'm not really able to solve, and can't find answers to, since it's pretty specific. I think my problems could be resolved after 15 to 30 mins of help by someone experienced with the involved aspects. If anyone feels like helping me out, please contact me.
# Email: jeroendedauw at gmail dot com
# Skype: rts.bn.vs
# Xfire: bn2vs
# Msn: jeroendedauw at gmail dot com
# Google talk: jeroendedauw
Cheers!
Jeroen De Dauw
---
Forums ; Blog ; Wiki
---
70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!
|
|
|
|
|
Come on, you've been a member long enough to know how it works. Post a piece of code, describe the problem and get an answer.
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
Indeed. I know that. But if you try something a few times, at multiple locations, and it fails, you should think of changing tactics, no?
My problem is more then 3 lines of code, and I really think I can't post it all here. Furthermore, since I'm not really sure on how to solve my problem, I can't determine which are all the relevant parts.
Jeroen De Dauw
---
Forums ; Blog ; Wiki
---
70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!
|
|
|
|
|
jeroen de dauw wrote:
My problem is more then 3 lines of code, and I really think I can't post it all here
is sort of different from your OP,
jeroen de dauw wrote: I've run into some things now that I'm not really able to solve, and can't find answers to, since it's pretty specific
To be honest, you seem to be strugglng to even explain the problems, which does make it difficult to help. I can't honestly see anyone contacting you direct under any circumstances, but particularly as you haven't really explained what is wrong.
Anyway, good luck
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
hi all, i need to export lakhs of records to excel, if i use the following code means, it doesn't throws any error,
select top 50000 * from dbo.CustomerDetail
but instead if i use
select * from dbo.CustomerDetail (it contains more than 10lakhs of records), it throws me an error.... Significant loss of functionality - the workbook contains data in cells outside of the row and column limit. data beyond 256(IV) columns by 65,536 rows will not be saved.....
my need is, if i have a table, it contains 70,000 records, i need to export it to excel, at that time it should automatically split the datas to two worksheets (which means 65000 in sheet1 and remaining 5000 in sheet2)...
code snippet in vb.net:
Imports Microsoft.Office.Interop.Excel
Imports System.Data.SqlClient
Imports System.Threading
Public Class Form1
Dim dtstart As DateTime = DateTime.Now
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strUniqueParamId As String
strUniqueParamId = System.Guid.NewGuid().ToString
Dim xThread As New Thread(AddressOf excelcheck)
xThread.Name = strUniqueParamId
xThread.Start()
MessageBox.Show("Generating")
Timer1.Start()
Thread.Sleep(1700)
'MessageBox.Show(Environment.TickCount.ToString());
End Sub
Sub excelcheck()
' Create the Excel Application object
Dim excelApp As New ApplicationClass()
' Create a new Excel Workbook
Dim excelWorkbook As Workbook = excelApp.Workbooks.Add(Type.Missing)
Dim sheetIndex As Integer = 0
Dim col, row As Integer
Dim excelSheet As Worksheet
Dim sqlcon As New SqlConnection("server=SHRIGI104\SHRIUNO0301;database=Test;uid=sa;pwd=welcome3#;")
sqlcon.Open()
Dim ds As New DataSet
Dim Da As New SqlDataAdapter()
Dim sqlcmd As New SqlCommand
sqlcmd.CommandType = CommandType.StoredProcedure
sqlcmd.CommandText = "SampleExcel"
sqlcmd.Connection = sqlcon
Da.SelectCommand = sqlcmd
Da.Fill(ds)
sqlcon.Close()
' Copy each DataTable as a new Sheet
For Each dt As System.Data.DataTable In ds.Tables
sheetIndex += 1
' Copy the DataTable to an object array
Dim rawData(dt.Rows.Count, dt.Columns.Count - 1) As Object
' Copy the column names to the first row of the object array
For col = 0 To dt.Columns.Count - 1
rawData(0, col) = dt.Columns(col).ColumnName
Next
' Copy the values to the object array
For col = 0 To dt.Columns.Count - 1
For row = 0 To dt.Rows.Count - 1
rawData(row + 1, col) = dt.Rows(row).ItemArray(col)
Next
Next
' Calculate the final column letter
Dim finalColLetter As String = String.Empty
Dim colCharset As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Dim colCharsetLen As Integer = colCharset.Length
If dt.Columns.Count > colCharsetLen Then
finalColLetter = colCharset.Substring( _
(dt.Columns.Count - 1) \ colCharsetLen - 1, 1)
End If
finalColLetter += colCharset.Substring( _
(dt.Columns.Count - 1) Mod colCharsetLen, 1)
' Create a new Sheet
excelSheet = CType( _
excelWorkbook.Sheets.Add(excelWorkbook.Sheets(sheetIndex), _
Type.Missing, 1, XlSheetType.xlWorksheet), Worksheet)
excelSheet.Name = dt.TableName
' Fast data export to Excel
Dim excelRange As String = String.Format("A1:{0}{1}", finalColLetter, dt.Rows.Count + 1)
excelSheet.Range(excelRange, Type.Missing).Value2 = rawData
' Mark the first row as BOLD
CType(excelSheet.Rows(1, Type.Missing), Range).Font.Bold = True
excelSheet = Nothing
Next
' Save and Close the Workbook
excelWorkbook.SaveAs("C:\BCP\sss.xls", XlFileFormat.xlWorkbookNormal, Type.Missing, _
Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlExclusive, _
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing)
excelWorkbook.Close(True, Type.Missing, Type.Missing)
excelWorkbook = Nothing
' Release the Application object
excelApp.Quit()
excelApp = Nothing
' Collect the unreferenced objects
GC.Collect()
GC.WaitForPendingFinalizers()
MessageBox.Show("Genearted Sucessfully")
Timer1.[Stop]()
Dim dtEnd As DateTime = DateTime.Now
Dim ts As TimeSpan = dtEnd - dtstart
MessageBox.Show("Mins:" + ts.Minutes.ToString() + "" + "Secs:" + ts.Seconds.ToString())
End Sub
End Class
Sample Stored Procedure:
USE [Test]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
alter PROCEDURE [dbo].[SampleExcel]
AS
BEGIN
select top 50000 * from dbo.CustomerDetail
select top 50000 * from dbo.CustomerDetail
select top 50000 * from dbo.CustomerDetail
select top 50000 * from dbo.CustomerDetail
select top 50000 * from dbo.CustomerDetail
select top 50000 * from dbo.CustomerDetail
END
GO
the above sp should be re-written as in single select statement
like "select * from dbo.CustomerDetail"....
pls need the help very soon...
modified on Thursday, December 10, 2009 6:42 AM
|
|
|
|
|
1. Having that much records in an excel file! Why?
2. Why are you using interop? You can connect to the excel file through OleDb Connection and export everything to it through one insert command.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
Well, your choices are to change your proc to select all the data and put some loop method in your code to output 65,000 records per sheet and start a new sheet, OR use dynamic sql to generate the appropriate number of selects and then execute them within the stored proc. I assume your table has a unique key that you can use to control the selection of each 50,000 rows?
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
You may want to do a little test first to see how much of your data you can actually fit in a WORKBOOK, not a worksheet.
Yeah, you're going to exceed the number of rows available in a single sheet, and that's handled with a bit of work on your part. But, you're bigger problem is that you're probably going to run Excel out of memory before you get through all of your customers.
The test is easy. Take a small sample of records from your database and export them to an Excel sheet. Then copy and paste those records over and over again filling up the sheet as much as possible. Then create a new sheet and paste the records into that, filling up the sheet as much as possible. I think you'll find that you run Excel out of memory fairly quickly and long before you get through all of your customers.
|
|
|
|
|
I'm not sure about the memory issues, as a powerful enough machine should solved that problem, however it sounds as if you are using Excel 2003.
Excel 2003 is limited to 65,536 rows by 256 columns per worksheet. The number of worksheets is only limited by available memory.
If you move to Excel 2007 you can go up the the limit of 1,048,576 rows by 16,384 column per worksheet, with the number of worksheets is limited by available memory.
So either loop and create multiple sheets, or upgrade to 2007. Either way ensure you have a shed-load of memory available.
Excel 2003 Limits[^]
Excel 2007 Limits[^]
|
|
|
|
|
How to retrieve an email using pop3??There is no class pop3 and what is the best method??
|
|
|
|
|
You could have tried this[^] first, and read through some of the suggestions available.
|
|
|
|
|
I have a generic class that I am trying to instantiate through a non-generic static method, but I am having some problems getting the type inference to work. Does anyone see some way to resolve this?
Public Class MirrorObservableCollection(Of T)
Inherits ObservableCollection(Of T)
Friend Sub New(ByVal base As IList(Of T), ByVal mirror As Func(Of T, T))
End Sub
End Class
Public NotInheritable Class MirrorObservableCollection
Private Sub New()
End Sub
Public Shared Function Create(Of TItem, _
TList As {INotifyCollectionChanged, _
IList(Of TItem)})( _
ByVal base As TList, _
ByVal mirror As Func(Of TItem, TItem)) _
As MirrorObservableCollection(Of TItem)
Return New MirrorObservableCollection(Of TItem)(base, mirror)
End Function
End Class
Dim mirror = Function(s As String) s.ToUpperInvariant()
Dim base = New ObservableCollection(Of String)()
Dim m1 = MirrorObservableCollection.Create(Of String, _
ObservableCollection(Of String))(base, mirror)
Dim m2 = MirrorObservableCollection.Create(base, mirror)
EDIT: I tried some other things and found a few ways to make it work. Mixing variables initialized with lambdas and generic inference is not good for your health.
Dim asFunc As Func(Of String, String) = Function(s) s.ToUpperInvariant()
Dim m3 = MirrorObservableCollection.Create(base, asFunc)
Dim m4 = MirrorObservableCollection.Create(base, Function(s As String) s.ToUpperInvariant())
Dim m5 = MirrorObservableCollection.Create(base, Function(s) s.ToUpperInvariant())
Poking around in Reflector shows that mirror is of type AnonymousDelegate(Of string, string) . For those that are interested, my conclusions about what is going on are:
m1) The compiler knows that it needs Func(Of string, string) and will wrap mirror accordingly.
m2) The compiler has not been able to figure out what type to use for TItem and thus if the annonymous delgate signature will match.
m3) The compiler is given a Func(Of string, string) which it will use to deduce that TItem is string and goes from there.
m4) The compiler is given a lambda that is string ->string . There is some voodoo magic to combine lambda signature generation with generic inference and it all works.
m5) The compiler is given a lambda that is ???->???. It cannot determine what type the parameter is and thus assumes object. The error actually given is that the lambda parameter type cannot be determined, but also mentions that base does not implement IList(Of Object) .
What surprises me most is that in neither of the error cases does it seem that the compiler was able to deduce TItem from base , which implements IList(Of String)
|
|
|
|
|
hi, i don't know much about .net framework programing, and i want to learn how to use it but i don't know if i can use c++ with it which is the programing language that i know, i know vb as well but i prefered c++, is there a posibility to use .net framework in pure c++ without using those languages like c#, j# and changing it's syntax like c++/cli and all that stuff or do i need a diferent compiler for that purpose,also want to know if i can mix c++ standard libraris with .net fwrk's ones thank you
|
|
|
|
|
Yes, choose a CLR project type and away you go...
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
As Davey said, use the CLR option and that's a start.
Member 4730435 wrote: if i can mix c++ standard libraris with .net fwrk's ones thank you
Though I have not mixed standard with the .net libraries, I suspect you can through some .dll magic.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
From what I have seen of Managed C++ I have been able to lift code straight from unmanaged C++ and paste it straight in, header files and all. Mind you I just wanted the functionality from some C++ code I found online and the only compiler I had available was Visual Studio. Worked first time.
Managed C++ can of course leverage the .Net runtime libraries as well.
|
|
|
|
|
hi i have one problem .
how i can replace string for image for example :
i write ":)" and i wan't replace to the image
how can i do in a textbox or richtextbox ?
|
|
|
|
|
Can't be done in a TextBox.
Use Google to find an RTB solution, and you discover this one[^] and many others.
|
|
|
|
|
Why can't we make an event in c# without a delegate as eventhandler, like you can in vb.net ?
Learning without thought is labor lost; thought without learning is perilous. (Confucius)
|
|
|
|
|
Events in C# and VB.NET work the same way. If you're refering to the WithEvents keyword, it's just syntactic sugar for having the manual stuff done for you.
|
|
|
|
|
If you don't want to bother creating your own custom delegate you have two other choices in c#
1. Use an inline delegate.
2. Use Generics eg. EventHandler<T>
In VB.Net you also have two options in addition to creating a custom delegate>
1. Use Generics
2. Use WithEvents
WithEvents works rather differently as it gives you rather more than just syntactic sugar, it also deals with reattaching the event handlers to the new object if you change the object referenced. You can even define the event handlers before initialising the object that raises the events.
In C# you have to do that yourself, and you have to have an instance before you can hook up events.
So, C# or VB.NET you can roll your own.
C# you get inline delegates
VB.NET you get less code for complicated event handling scenarios.
Personally I would rather have a little more code that shows me what is really going on. Then it is easier to realise I didn't need half of it in the first place!
|
|
|
|
|
Excellent reply.
Again c# seems to be a lot clearer.
Learning without thought is labor lost; thought without learning is perilous. (Confucius)
|
|
|
|
|
Thanks.
I use c# for my own projects, and VB.Net at work, so I get to see both sides of the coin, and struggle to get the two to do the same. I do prefer the flexibility and control in c#, but some of the RAD tools embedded in VB.Net are excellent.
I wish it were possible to code classes in the same project in different languages so I could use the most appropriate one for the task at a class level. If that included managed C++ for some of the restricted stuff like Extended MAPI then even better.
|
|
|
|
|