|
I prefer to have a system-wide, non-application-specific configuration file that lists the databases available to the system.
Such a file can be stored in the Application Data directory for the user or all users -- so all users can have the same settings, or each user can have his own.
And I don't store actual connection strings; I store the information required to cobble one up for the requested database engine.
Here's an older version:
<DATABASES>
<CT TYPE="SQLSERVER" SERVER="LOCALHOST\SQLEXPRESS" NAME="CoconutTelegraph" />
<DTER TYPE="SQLSERVER" SERVER="LOCALHOST\SQLEXPRESS" NAME="DTER" />
<DDLTEST TYPE="SQLSERVER" SERVER="LOCALHOST\SQLEXPRESS" NAME="DDLTEST" />
<FIREBIRD TYPE="FIREBIRD" SERVER="LOCALHOST" NAME="C:\Program Files\Firebird\examples\empbuild\employee.fdb" USERNAME="SYSDBA" PASSWORD="masterkey" />
<MPG TYPE="SQLSERVER" SERVER="LOCALHOST\SQLEXPRESS" NAME="MPG" />
<MR TYPE="SQLSERVER" SERVER="LOCALHOST\SQLEXPRESS" NAME="MusicLibrary" />
<RUBBISH TYPE="SQLSERVER" SERVER="LOCALHOST\SQLEXPRESS" NAME="Rubbish" />
<SA TYPE="SQLSERVER" SERVER="LOCALHOST\SQLEXPRESS" NAME="VersionControl" />
<WORDSEARCH TYPE="ACCESS" NAME="C:\projects\wordsearch\bin\release\WordSearch.MDB" PASSWORD=":badger:" USERNAME="admin" USERPASSWORD="" />
</DATABASES>
And here's a version I'm working with this week:
<Databases>
<Junk Provider="SqlServer" Parameters=".\SQLEXPRESS,Junk" />
</Databases>
This allows the application to be more database agnostic -- it doesn't need to know which database engine is in use.
|
|
|
|
|
thanx for the response but I'm afraid I didn't get it exactly, could u elaborate more on how to use this piece of code and where to use it ?
thanx alot!
|
|
|
|
|
After read the Essential C#, I am still puzzled why C# has the event keyword.
The Delegate is similiar with the function pointer in C/C++ and can make the function of programming needed. So I think that the event is unwanted.
right?
modified on Wednesday, July 7, 2010 11:33 AM
|
|
|
|
|
yu-jian wrote: So I think that the event is unwanted.
right?
Wrong. Sorry, but event is a specialist form of multicast delegate - to achieve this specialism, the event keyword was necessary.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
You're wrong, and that's probably why you're not working on the C# team at Microsoft.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Yes, but... the event keyword allows special handling of the multicast delegate:
0) Only the defining class can raise/call/execute the event.
1) All other classes are required to use the += and -= operators.
You are welcome to use non-event multicast delegates in your code if you like. Come back and let us know how it goes.
|
|
|
|
|
Your answer is good. I know event is useful,
Thanks very much.
|
|
|
|
|
I am working with .net application. I have few informations in string. Now i would like to put this string into html tags. Lets say i have array of names and i would like to write them down in html paragraph. How could i do this in c# code?
|
|
|
|
|
You can use response.write() function to do that.
string htmltodisp="here is my string to display in paragraph";
Response.Write("<p>" + htmltodisp + "</p>");
Hope this will help!
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
It depends how you want to format the data. Suppose for instance that you want each name in a paragraph, a quick and dirty hack to do this would be to use something like:
StringBuilder sb = new StringBuilder();
foreach(string name in names)
{
sb.AppendFormat("<p>{0}</p>", name);
} Alternatively you could look at the HtmlTextWriter[^] class to do the job properly.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Pete O'Hanlon wrote: Alternatively you could look at the HtmlTextWriter[^] class to do the job properly.
I think he's better off writing it the frist way. What benefit does the HtmlTextWriter have? I diodn't see any, myself.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
I wasn't sure if he was working in an ASP.NET environment. If he is, and he's developing a custom control (again - unsure, so I've gone for the safe case here) then the HtmlTextWriter (and children such as the XhtmlTextWriter) are a good fit.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
I would use WebUtility.HtmlEncode from System.NET library.
It provides a correct encoding of '<','>' and '&' ,...
Your html code would have bugs, if your string contains one of the chars and you don't encode them.
You can decorate the converted string with html tags.
|
|
|
|
|
Hey Guys
I'm using the RegEx to do some pattern matching, but I'm after finding one of 2 specific strings.
At the moment I'm using Regex reg1 = new Regex("FIRST[ ]+STRING");Regex reg2 = new Regex("SECOND[ ]+STRING");
Is there a way I could get the Regular Expression to say match exact string A OR exact string B in the same statement? (eg Regex exp = new Regex("ThisString or ThisString");
Thank you in advance
oooo, the Jedi's will feel this one....
|
|
|
|
|
Regex exp = new Regex("(ThisString)|(ThatString)");
Will do it nicely.
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
Thats it???
So simple. I'm kicking myself now. Thank you.
oooo, the Jedi's will feel this one....
|
|
|
|
|
You're welcome - technically you don't need the brackets, but I always feel they help to make it more readable (if a regex can be described as readable... )
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
Before I forget - have a look at Expresso[^] - it examines, creates and explains regular expressions. It works, it helps you understand how they work, and it's free.
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
Excellent. Thanks. I'm new to regular expressions, and they appear very alien so far.
Muchas Gracias
oooo, the Jedi's will feel this one....
|
|
|
|
|
Guys,
I am using C# with MSS 2005. I need to generate a sequential number for a field (ItemNo) in the format ddmmyyyy000000x where x is a sequencial number eg (020520100000001,020520100000002, 020520100000003 ...) for records generated on May 2, 2010.
Can any one help in this regard.
|
|
|
|
|
So do it - what is the problem?
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
I have something similar in VB6 with MDB but have difficulty using C# and MSS. See my VB6 code below and advice on how to produce something similar in C#.
Public Sub GenerateCode(ByRef Coder As String)
Dim strMar As String, intApr As Integer
Dim strJul As String
Coder = UCase(Coder)
Dim rs As New ADODB.Recordset
Dim cn As New ADODB.Connection
On Error GoTo AddNewErr
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Manager.mdb"
rs.Open "select ItemNo from Items where left(ItemNo,8) like '" + Coder + "' order by ItemNo asc", cn, adOpenKeyset, adLockOptimistic
If rs.RecordCount <> 0 Then
rs.MoveLast
If Left(Trim(rs.Fields!ItemNo), 8) = Coder Then
strMar = Right(Trim(rs.Fields!ItemNo), 6)
strMar = Val(strMar) + 1
strMar = CStr(strMar)
If (6 - Len(strMar)) <> 0 Then
strMar = String$(6 - Len(strMar), "00000") & strMar
End If
Else
strMar = "000001"
End If
Else
strMar = "000001"
End If
Coder = Coder & strMar
Editor = Coder
Set rs = Nothing
Set cn = Nothing
Exit Sub
AddNewErr:
MsgBox Err.Description, vbExclamation, "Error Report"
End Sub
|
|
|
|
|
So, what you are doing is:
1) Read the last record (presumably for this month) from your database.
2) If it doesn't exist, use a default of 1.
3) If it does, strip out the last 6 characters, convert to int, add one to it and use that.
4) Reattach that to the code for this month.
Ignoring that you seem to have a fetish over naming your variables after months of the year, and the "str" prefix is a bit of a waste of time, since half way through you hold integers in them.
What is the bit that is giving you problems? Apart from the whole approach, which is frankly rubbish?
If you must have an item number that is a string, with a date and a sequence number, then:
1) Read the last record.
2) Assume none: set integer default to 0 in variable called nextSequenceNumber
3) If record exists, extract last 6 characters, and parse to int. Store in nextSequenceNumber.
4) Return date code + (nextSequenceNumber + 1).ToString("000000")
Assume the database will contain corrupt data - use TryParse rather than parse, and log any failures. Try to deal with them nicely.
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
There is a lack of PRE tags, semi-colons and curly braces. These codez don't belong here.
|
|
|
|
|
PRE tags, semi-colons and curly braces are the least of the problems! Even by VB standards, that is some clumsy code...
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|