|
Try the following:
textBox1.Text = textBox1.Text.Insert(textBox1.SelectionStart, DateTime.Today.ToString());
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Hey guys, I just wanted to get some input on this method I wrote to parse data. Normally every time you want to parse data coming from a datasource, we need to do something like:
int myInt = 0;<br />
try<br />
{<br />
myInt = (int)ds["columnName"];<br />
}<br />
catch{}<br />
<br />
bool myBool = false;<br />
try<br />
{<br />
(bool)ds["columnName"];<br />
}<br />
catch{}<br />
etc....
This is of course gets very ugly the more data you are grabbing. Initially in c# 1.1 I had written a class with a bunch of methods for each variable type. So for the int example above I would use:
public int ParseInt( string sValue, int defaultValue )<br />
{<br />
try<br />
{<br />
return int.Parse( sValue );<br />
}<br />
catch<br />
{<br />
return defaultValue;<br />
}<br />
}
As well as an overloaded method
public int ParseInt( string sValue )<br />
{<br />
return ParseInt( sValue, 0 );<br />
}
So the above example would now look like:
<br />
int myInt = ParseInt( ds["columnName"].ToString() );<br />
bool myBool = ParseBool( ds["columnName"].ToString() );<br />
For the record, I realize this was not a good solution, as the .ToString() method would throw an exception if ds["columnName"] was null. I should have had the methods take an object as the argument, and try (int)object inside the method instead of int.Parse(). Regardless, this worked well but you needed to write 2 methods for each variable type. With the release of c# 2.0 and generics, I decided to make a more flexible version. I came up with the following 2 methods that will handle any variable type.
<br />
public static T Parse<T>( object objToParse, T defaultValue )<br />
{<br />
try<br />
{<br />
return (T)Convert.ChangeType( objToParse, typeof( T ) );<br />
}<br />
catch<br />
{<br />
return defaultValue;<br />
}<br />
}
And the overloaded method
public static T Parse<T>( object objToParse )<br />
{<br />
return Parse<T>( objToParse, default( T ) );<br />
}
So now my above examples become:
int myInt = Parse<int>( ds["columnName"] );<br />
bool myBool = Parse<bool>( ds["columnName"] );
MUCH cleaner than before, and you can pass it any type of object. This seems to be a perfect solution, but I am posting to see if anybody sees anything wrong with this. We are using this method pretty heavy now @ my current job, and I just want to be sure I haven't overlooked anything. Thanks for the help.
|
|
|
|
|
This is .NET code? So there is some reason you cannot use Typed DataSets?
led mike
|
|
|
|
|
Well this can be used in places where Typed Datasets would not make sense; form inputs for example. Also we use a lot of DataReaders as opposed to DataSets, so it makes sense to use something more universal.
|
|
|
|
|
Let's say i want to make a proxy tester/IP scanner/website checker or whatever, how can i check if the server/ip/domain exists? i tried using ping but i couldnt find relevant references.
help would be appreciated.
|
|
|
|
|
Many servers and firewalls have ping disabled.
If you want to check if a web site is up, you should request a page from it. Just checking that the server is running does not guarantee that the web server is running or that the web site is working.
---
single minded; short sighted; long gone;
|
|
|
|
|
Well, how do i do that then? o_O
|
|
|
|
|
There's really no reliable way to verify it at all, except for just trying it and see what happens.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
You can use the WebRequest class or the WebClient class.
---
single minded; short sighted; long gone;
|
|
|
|
|
Hello gurus,
I'd like to know how I can enumerate the SQL Server instances on the local machine?
How can do this in C#?
For example, if I have installed the default instance, an the instance named "TOTO" on my system, I wish to see the two names in my enumaration (local and TOTO).
Best regards.
Fred.
Note: the sample in VS 7.1 that uses ODBC does not work with SQL Server 2005 and VS2005.
There is no spoon.
|
|
|
|
|
|
I was talking about this sample. it does not work on VS 2005 & SQL Server 2005...
There is no spoon.
|
|
|
|
|
Did you try to convert project for VS2005?
|
|
|
|
|
yes, I have converted it.
I have started the browser service and I could run it.
But it enumerates the SQL Servers on the local network, not the instances on the local machine.
For example, if I have two instances (default and TOTO), I should get the MSSQLSERVER service that runs for the default instance, and MSSQLSERVER$TOTO service that runs for the TOTO instance... I wish to retrieve this information.
Best regards.
There is no spoon.
|
|
|
|
|
|
Details
I used C#.Net 2005 and SQL 2000 as back end.
I wrote stored procedure to retrieve record (for the report) from the server.
I used Crystal Report (C#.Net 2005) to prepare the report and CrystalReportViewer to display it.
I also wrote codes in “Code View” of a Form to load the report.
The report runs perfectly in isolation.
The report also runs very well from the Application prior to deployment.
Problem
The report however, could not be loaded after deployment.
It generate an error “Load Report Failed”
Assumption
I suspect the absence of required file(s) that should be added during deployment in order to aid the loading of a crystal report file, since the report runs in “IDE” before deployment or do you think otherwise?
• Please assist in solving my problem so that I can deploy appropriately.
Banjo Ayorinde
|
|
|
|
|
Hi guys
I have created a webservice in VS2003, and I have some webmethods and classes in it. Those webmethods are shown in the client applicaiton after adding a web reference to it, but not the classes i created in web service.
How do I make my classes in WS to display in the client application?
Can anyone help in this?
Here is the sample code:
namespace WebserviceNS
{
public class MyService: System.Web.Services.WebService
{
[WebMethod]
public void MyMethod()
{
//...//
}
}
public class MyClass
{
public MyClass()
{
//...//
}
public void ClassMethod()
{
//...//
}
}
}
Here MyClass is not shown in the client side. Do I have to declare any attribute for displaying?
Thanks
Muthu.
|
|
|
|
|
try something like this:
public class MyClass : Microsoft.Web.Services2.WebServicesClientProtocol,IMyClass
IMyClass is an interface you declare for your class.
|
|
|
|
|
Hi
When you create a webservice and import it in another project as WebReference, a Wrapper - Dll is automatically created (similarly like when you reference a COM - Library).
This Library Implements the WebService as Class AND all Types that are returned by any call of a Method of that webservice.
so.
if you have a class in your Web-Service -dll that is never returned (or used as Parameter) by a call of the webservice, you will not get this class on the client side.
greets
m@u
|
|
|
|
|
hi!
I've recently started to try to learn programming in C#. Never programmed before - but it is fun.
Most things go well, but now I've a problem as follows:
I've got a windows form with a richtextbox object (in fact it's the richtextboxextended - object I've found on this site;))
I've got an sql-server database
I'm using a stored proc on the server for storing data
in one table of this database is a field, which is formated in ntext (also have one in binary format)
I want to store the data which is in the richtextbox to the database field.
Normally I do the following:
cmdsql.Parameters.Add("@fb_PP_VL",this.ochk_VL.Checked);
now I want to add a parameter for the rtf-field also.
I've thought this to be the right form:
cmdsql.Parameters.Add("@fm_PP_Note",Convert.ToByte(this.ortb_Note.RichTextBox.Rtf));
but this is definitely wrong
So what do I have to do?
Salgerion
|
|
|
|
|
The table in the database must first hold another field for storing the rich text of your RTB object. The field should be of type varchar(255) if your text never extends more than 255 characters. If 255 chars aren't enough, you can instead use a field of type text.
Once this is in place, you can add a parameter to your Stored Procedure, and have the procedure write the inputted text to the database. You do not need to convert the rich text box's RTF to bytes first. (FWIW, you were trying to conver the whole RTF to a single byte, which of course won't work.) Just pass the RTF in as the parameter value, no conversion needed, and it should work.
|
|
|
|
|
Thanks a lot. it's working now
Salgerion
|
|
|
|
|
hi
i have a free table which is in foxpro...
i want to read it
is it possible if so how?????????
thanks
|
|
|
|
|
What do you mean by free?
Anyway, you should be able to read it via odbc.
|
|
|
|
|