|
How would you do it in VB? Open a connection to the database, execute a command, iterate through the results, instantiate a class, add to a collection
List<MyClass> myClasses = new List<MyClass>();
IDataReader dr = cmd.ExecuteReader();
while(dr.Read())
{
MyClass cls = new MyClas();
cls.ID = dr.GetInt(0);
...
myClasses.Add(myClass);
}
only two letters away from being an asset
|
|
|
|
|
it looks really easy like that. I'll give it a try when I get back to work. In VB6 I would raise a class 'Inventory' containing all the fields I've already mentioned. The class manager would then apply all the 'get and 'set' attributes to the class members (I'm probably not using the right descriptions here). I would then raise a collection of class Inventory. I then would connect to my database, return a recordset of Inventory, and iterate through it, adding the information into the fields of the collection:
do until recordset.eof = true
inventory collection .add (the columns of the inventory table)
loop
Thanks for you help
C# is great....
|
|
|
|
|
It will work pretty much the same way in C#, the code only changes slightly. You should have specified you meant VB6, I think the other reply assumed you were going from VB.NET to C#, because VB6 has been obsolete for almost a decade.
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.
|
|
|
|
|
Thanks Christian, I'm going to try it now. sorry about the misunderstanding about VB6, I tend to think in that language. I know it's been obsolete for a long time, but there is still lots of VB6 code out there. I've not forgiven Uncle Billy for ditching it like that, although I can understand why.
Chiefy
|
|
|
|
|
I am reading an Excel file into a dataset, then later into an Access table. All being done using C#. The first thing I do is load a dataset with the Excel data. There is a column in the Excel file called SEQNUM, and the corresponding Access column's name is the same. It's a DateTime field. The data in the Excel file appears to be a datetime.
When I look at the dataset with the DataSet Viewer, the data in the SEQNUM column looks like this:
-7017917/858993439/08
-7017918/858993451/08
3/-29/34
3/-28/34
1/-429496757/35
-20/-429496747/37
-20/-429496746/37
-13/-429496759/37
-13/-429496758/37
2/-429496749/36
2/-429496748/36
2/-429496747/36
-15/-429496758/38
-15/-429496757/38
0/-429496748/37
0/-429496747/37
.
.
.
When I show formulas in the Excel file the data looks like this:
35225781579640
35225781730541
35225781947742
35238693176684
35241364002568
35241364163669
35241364316770
These number appear to be too large to be an Excel date. Anyone know what this is? Is the conversion to a dataset screwing up the data?
Thanks
Everything makes sense in someone's mind
|
|
|
|
|
Kevin Marois wrote: These number appear to be too large to be an Excel date. Anyone know what this is? Is the conversion to a dataset screwing up the data?
Dates in Excel are stored as real numbers where the integer portion is the date in days since the epoch (1 January 1900) and the fractional portion is the time as a fraction of 24 hours, thus .5 is 12:00 noon. So when you read these values from the spreadsheet you will need to convert them to proper DateTime values before storing them in your dataset.
|
|
|
|
|
hi every one
how to create menu with directx in c#
thanks
|
|
|
|
|
with code.
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.
|
|
|
|
|
Hello,
How we can test if a directory is empty? thank you verry mutch.
|
|
|
|
|
If Directory.GetFiles[^] is not returning any data, consider it is empty.
Best wishes,
Navaneeth
|
|
|
|
|
const string MYDIR = @"C:\MYDIR";
string[] files = Directory.GetFiles(MYDIR);
string[] dirs = Directory.GetDirectories(MYDIR);
if(files.Length == 0 && dirs.Length == 0)
{
}
|
|
|
|
|
Hi,
before .NET 4.0:
the easiest way is testing Directory.GetFileSystemEntries().Length==0 as this method returns the names of all files and folders.
and yes it is a pity you have to ask for a potentially huge array of data just to get a true/false result.
the alternative is to use P/Invoke and use FindFirstFile (not sure if and how that works for subdirectories).
since .NET 4.0 there are new siblings to GetFileSystemEntries and the like (see EnumerateFileSystemEntries) that return results only one at a time and don't burden the CPU and memory that much, as you can opt out right away.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? 59.24% waren verstandig genoeg om NEEN te stemmen; bye bye viaduct.
|
|
|
|
|
I want totransfer files from a client to another, using socket programming+c#?
|
|
|
|
|
So on what part are you facing problem?
Best wishes,
Navaneeth
|
|
|
|
|
never heard about google ?
you can find also in codeproject, there are lots of sample for that.
|
|
|
|
|
Hi
I am writing a small class that covers a multitude of areas for CD use.
I am using IMAPI2, and managed to get the buring, formatting and erasing process going, but I haven't been able to find anything for reading from a disc.
Does IMAPI2 do this, or is there another way of doing this?
Please help!
Thanks
|
|
|
|
|
|
Hi
I know about this article, but it does not provide for reading data from a CD into an application, which is what I want to do.
The solution, I am looking for is a way to read data off a disc into a database. Therefore, I need to stream data off a disc into a object.
Thanks
|
|
|
|
|
|
Hello,
I frequently write many SQLs and would like to embed in C# code (SSMS 2005/VS.NET 2005). There was macro which would let me select the code and hit a shortcut to format it into C# code. Has anyone seen where it is now?
Thanks,
Raghu.
You can never try. You either do it or you don't.
|
|
|
|
|
Do I understand that you want a macro to copy SQL statements into a C# file?
I thought it was Ctrl+C, Ctrl+V
only two letters away from being an asset
|
|
|
|
|
Hmm... haven't heard that before, but I'll give it a try...
I was referencing converting a SQL statement to C# string...
But, here's what I came up with in case someone needs this... Assign this macro a short cut of of Ctl+Shift+F3
It converts
select *
From Status
From ActivityStatus ActStsId=StsId
to
string sql = " select * "+
" From Status "+
" From ActivityStatus ActStsId=StsId";
Macro is as follows.
Sub SQL2CSharp()
Dim selection As EnvDTE.TextSelection
Dim startPoint As EnvDTE.EditPoint
Dim endPoint As TextPoint
Dim quoteStart As String
selection = DTE.ActiveDocument.Selection()
startPoint = selection.TopPoint.CreateEditPoint()
endPoint = selection.BottomPoint
quoteStart = """"
DTE.UndoContext.Open("SQL 2 CSharp")
Try
startPoint.Insert("string sql = """)
Do While (True)
Dim line As Integer
line = startPoint.Line
startPoint.Insert(quoteStart)
startPoint.EndOfLine()
If (line = endPoint.Line) Then
startPoint.Insert(quoteStart & ";")
Else
startPoint.Insert(quoteStart & "+")
End If
startPoint.LineDown()
startPoint.StartOfLine()
If (line = endPoint.Line) Then
Exit Do
End If
Loop
Finally
' If an error occurred, then make sure that the undo context is cleaned up.
' Otherwise, the editor can be left in a perpetual undo context.
DTE.UndoContext.Close()
End Try
End Sub
You can never try. You either do it or you don't.
|
|
|
|
|
Why would anyone need or want this? You SHOULD NOT be using inline SQL at all.
only two letters away from being an asset
|
|
|
|
|
Are you suggesting I should use the alternatives for SQL like SPs, functions, views etc?
You can never try. You either do it or you don't.
|
|
|
|
|
Only if you want your applications to perform better, be more maintainable and more secure
only two letters away from being an asset
|
|
|
|