by cliper
Monday, December 06, 2010 3:19 PM
Sometimes, we need to do a quick true/false decision in our code...
PHP
|
$var = ($value == true) ? “it’s true” : “it’s false”;
|
C#
|
string value = ($isTrue == false ? “it’s false” : “it’s true”);
|
by cliper
Wednesday, August 20, 2008 9:08 PM
there was a time that I need to use the SQL Management Objects.
Good thing about these collection is that we can manage our MS SQL Server with ease.
I recommend using SMO in huge backup projects or batch updates/inserts/delete's or maybe managing stored procedures, views, triggers et al against databases. Just thought that smo objects was used in SQL Compare and related products from red-gates. I used their products for a while. You can find more info here.
I'll show you a good example that might help you get started.
First, you need to have the following assemblies:
Microsoft.SqlServer.ConnectionInfo.dll
Microsoft.SqlServer.Smo.dll
Microsoft.SqlServer.SmoEnum.dll
probably, if you leave the default installation directory of your MS SQL Server 2005 standard edition installation then you can find the assemblies in this directory
C:\Program Files\Microsoft SQL Server\90\SDK\Assemblies
These assemblies are available when installing Microsoft SQL Server 2005. If you don't have SQL Server 2005 standard edition installed, you can download the object collection from the "Feature Pack for Microsoft SQL Server 2005 - November 2005". Click here for details.
You only need to download the Microsoft SQL Server 2005 Management Objects Collection.
Scroll down to find the category. Hope Microsoft will not sue me for having this direct link to that:
XMO for x86
XMO for x64
Next, fire-up Visual Studio 2003/2005/2008 Pro/Express. Create new Project and select console application.
Download the project solutions below. Run the app.
b2b0c173-9b7d-47c0-bfbe-9e2584a8d000|0|.0
Tags:
C# | SQL Server
by cliper
Wednesday, June 25, 2008 11:27 AM
Well, sometimes we asked how can we passed request parameters in our web application?
So if we have http://cliper.boholcentral.com/?request_id=test we need to get "test"
In our classic ASP web application, we do like
Request.QueryString("request_id")
probably, ASP.NET still uses this syntax and the most readable syntax could be:
C#
Request["request"];
VB
Request("request_id");
fb6831ff-8c91-4c67-96f9-6b34e6cdf296|0|.0
Tags:
ASP.NET | C#
by cliper
Wednesday, June 04, 2008 7:04 PM
I’ve been a Participant of asp.net community forum for a while. I’ve been active in the MySQL forum and most developers keep asking the same question. I just thought this might help those new to MySQL connector.NET
Well parameters are variables that can hold values within your query strings. This enables us to pass values in our current query or from one statement to another.
Let’s just go to the point. What we have here is a table named MyTable.

And we have our insert statement as
INSERT INTO MyTable VALUES (null, ?ParName);
Now, what we want is to pass a value from ?ParName param. Let’s do the coding…
Assuming that we already set everything then our code might look like this…
MySqlConnection con = null;
MySqlCommand cmd = null;
string nameStr = "Sample value passed \”";
con = new MySqlConnection("server=localhost;database=db_name;uid=user;pwd=password;pooling=false;");
con.Open();
cmd = new MySqlCommand("insert into MyTable values (null, ?ParName);", con);
cmd.Parameters.AddWithValue("?ParName", (string)nameStr.Replace("\"", "^"));
cmd.ExecuteNonQuery();
con.Close();
Wow! really neat. We cast our value to string and we can even replace strings inside it.
Why not give it a try? Happy coding! Anyway, there’s much you can do with it. I just play dumb.
52a0f42c-49d0-421d-942e-b43b10933676|0|.0
Tags:
.NET | C#
by cliper
Wednesday, June 04, 2008 6:04 PM
Where’s C# Control Events? It’s gone!
Wait a sec, there’s something wrong with my Visual Studio. I can’t see the events that are available to my control just like Visual Basic.
Are you one of those who keep asking this question? Perhaps some of you wonder how to add Events in your application in C#.NET then this topic is for you.
Maybe this topic is just a waste of time but I hope this will stop scratching your head where to find the events in Visual Studio 2005 or the Express Editions and C#.NET.
(I would like to relate this post to the person named NWeb from asp.net forum. He wasted a day till he finds out how to pass parameters in MySQL. Lol)
There are few ways on how to create your events in C# with your Visual Studio 2005 or Express Editions. We can hook up events using Intellisense

type or initialize it yourself, or just enjoy the beauty of Visual Studio with a few mouse clicks.
In your Property windows, you can see an extra lightning icon in the right-side with a little “cute” tip labeled “Events”. See image below.

After clicking that icon, it will list available events. The good part is that you can name it yourself. Like if you want controlname_GotFocus to be controlname_WhenFocused you can easily type it in the field.
The other way of doing it is to initialize the event yourself. Before Visual Studio 2005 I used Visual Studio 2003. The InitializeComponent() method in VS 2003 can be shown in the Code view but right after VS 2005 it can only be seen when selecting it in the events selections.

(Initializing your events can be useful when starting to create your own system events).
So anyway, in our InitializeComponent method will create a delegate to represent our control event. Let’s say for example we want to handle the event for a Textbox GotFocus event then it should look like
textBox1.GotFocus += new System.EventHandler(textBox1_GotFocus);
and in our handler could look like
void textBox1_GotFocus(object sender, System.EventArgs e)
{
// statements here…
}
So that’s it. No big deal.
Good luck!