Sandeep & Vicky’s Archive » .Net

Archive for the ‘.Net’ Category

Hey Guys,

This is cool. The following code does a very simple and very important work for us. In all the programming languages, we follow a pattern of using capital letters to to differentiate between words while writing classes or making UI pages .i.e. instead of creating a class like class addnewstudent, we prefer class AddNewStudent. Now this can be easily understood by a programmer, but what abt a layman??????? The following code makes it easier for a layman and converts such strings into human readable format

Code

private string MakeStringReadable(string source)
{
StringBuilder sb = new StringBuilder();

char last = char.MinValue;
foreach (char c in source)
{
if (char.IsLower(last) &&
char.IsUpper(c))
{ sb.Append(‘ ‘); }
sb.Append(c);
last = c;
}
return sb.ToString();
}

27
Sep

How to convert String to double in ASP.Net

   Posted by: admin

Hi guys,

Converting a string to integer or double in .Net is very much similar to that in java.

Here is the code

double x=Double.Parse(“”+100.1);

Output

x=100.1

Hi guys,

I have  working with java for the past two years and never tried building application in.Net. Recently, we had a project which was to be done in .Net. We then just learned visual studio and found a very gr8 feature in it.

J#

.Net applications can be written in the java syntax by using J#.

It really kool…..all our database connectivity codes, server side codes which were written in java were easily transformed into a .Net application.

We can have .java extension files as well in our .Net web site.

That is the language independence feature of .Net….which makes it more user friendly and will obviously attract more developers to switch to .Net.

But still java rules

24
Aug

Commit and rollback in ASP.NET

   Posted by: admin

Database transactions can be committed and rolled back using front end tools like .Net or java. Here is a simple code to do so in c#.net

private void SQLCommandTransaction(string sServer, string sDB)
{
SqlConnection cn = new SqlConnection(“SERVER=” + sServer
+ “;INTEGRATED SECURITY=True;DATABASE=” + sDB);
SqlCommand cmd = new SqlCommand();
SqlTransaction trans;
// Start a local transaction

cn.Open();
trans = cn.BeginTransaction();
cmd.Connection = cn;
cmd.Transaction = trans;
try
{
// Insert a row transaction
cmd.CommandText =
“INSERT INTO Department VALUES(100, ‘Transaction 100′)”;
cmd.ExecuteNonQuery();
// This will result in an error
cmd.CommandText =
“INSERT INTO Department VALUES(100, ‘Transaction 101′)”;
cmd.ExecuteNonQuery();
trans.Commit();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
trans.Rollback();
}
finally
{
cn.Close();
}
}

Related Posts with Thumbnails