Welcome to AspAdvice Sign in | Join | Help

ADO.NET with C#

ADO.NET using C#. It is a Console application showing you how to loop over the rows in a DataSet and how to check if a Primary Key Exists in a table and finally we will use Find and Delete methods of the DataTable.Rows. DataRow rowFind = ds.Tables[0].Rows.Find(id);  

 
First of all we need data to play with. I am using Northwind Database
and here is the connection information.
 
string conStr ="Server=(local); Database=Northwind; Integrated Security=SSPI";
string query1 ="select customerid, contactName from customers";
string query2 ="select top 5 companyName from customers";
SqlConnection conn = new SqlConnection(conStr);
SqlDataAdapter da = new SqlDataAdapter(query1, conn);
ds = new DataSet();
For a Complete Article, please click here:
http://www.devtalklive.com/cmsnet/CDA/StoryPg.aspx?ID=9&Ver=8

 
First of all we need data to play with. I am using Northwind Database
and here is the connection information.
 
string conStr ="Server=(local); Database=Northwind; Integrated Security=SSPI";
string query1 ="select customerid, contactName from customers";
string query2 ="select top 5 companyName from customers";
SqlConnection conn = new SqlConnection(conStr);
SqlDataAdapter da = new SqlDataAdapter(query1, conn);
ds = new DataSet();
For a Complete Article, please click here:
http://www.devtalklive.com/cmsnet/CDA/StoryPg.aspx?ID=9&Ver=8
Sponsor

URL Validation

This is a simple URL Validation Application written in C#  

 Click here for a complete article:

http://www.devtalklive.com/cmsnet/CDA/StoryPg.aspx?ID=13&Ver=2

using System;
namespace CSharpProj {
public class WebSite
{
const string http = @"http//";
const string httpwww = @"http://www.";
string siteName;
string url;
string description;
public WebSite(): this("No Site", "No url", "No Description"){}
public WebSite(string newSite): this(newSite, "No url", "No Description"){}
public WebSite(string newSite, string newURL): this(newSite, newURL,
"No Description"){}
public WebSite(string newSite, string newURL, string newDesc)
{
this.siteName = newSite;
this.url = newURL;
this.description = newDesc;
Console.WriteLine(this.siteName + " " + this.url + " " + this.description)
;
}
public string ValidateUrl(string url)
{
if ((url.StartsWith("www.")))
{
return "[Passed without,so adding http]--> " + http + url;
}
if (!(url.StartsWith(httpwww)))
{
return "[Passed without,so adding httpwww]--> " + httpwww + url;
}
return "[Passed with httpwww]--> " + url;
}
public string ValidateUrl(ref string url)
{
if ((url.StartsWith("www.")))
{
return url = http + url;
}
if (!(url.StartsWith(httpwww)))
{
return url = httpwww + url;
}
return url;
}
}
public class WebSiteTester
{
static void Main()
{
string url = "google.com";
WebSite web = new WebSite("Hotmail", "http://www.hotmail.com");
string myurl = web.ValidateUrl("http://www.yahoo.com");
Console.WriteLine(myurl);
Console.WriteLine("Before: " + url);
web.ValidateUrl(ref url);
Console.WriteLine("After: " + url);
DateTime dt = Convert.ToDateTime("8/1/2005");
Console.WriteLine(string.Format("{0:MMMM yyyy}", dt));
//would print August 2005
}
}
}

Sponsor

Threading in .NET

I will discuss System.Threading namespace with a few simple Threading Console Applications.  

 
We will going to focus on only Thread class since this class represents our processing
threads. This class allows us to do everything, from managing a threads priority, to
reading its status.
Please click on the follwing link for the full article.
 System.Threading Namespace

 
We will going to focus on only Thread class since this class represents our processing
threads. This class allows us to do everything, from managing a threads priority, to
reading its status.
Please click on the follwing link for the full article.
 System.Threading Namespace
Sponsor

Dynamic Connection Strings in Reporting Services 2005

 Wouldn't it be nice to have one report and can display data from
different databases residing on different servers? Instead of creating a same report multiple times to be deployed on different servers, we can have one report and it can generate data from any database on any server.(if you are using stored procedures, make sure the same stored procedure exists in every database you are running the report against). So in the URL we can pass in the database name and server name for different clients for their specific data.
Please click here for the full article:
Sponsor

Using Multiple SqlDataReaders with a single open connection

   SqlDataReader drWDC;
   SqlDataReader drSC;
   SqlDataReader drCC;

   conn.Open();

   drWDC = cmdWDC.ExecuteReader();
   dgWDC.DataSource = drWDC;
   dgWDC.DataBind();
   drWDC.Close(); //must close the datareader before using a 2nd datareader
    
   drSC  = cmdSC.ExecuteReader();
   dgSC.DataSource = drSC;
   dgSC.DataBind();
   drSC.Close();

   drCC  = cmdCC.ExecuteReader();
   dgCC.DataSource = drCC;
   dgCC.DataBind();
   drCC.Close();

   conn.Close();

Sponsor
Posted by Bilal_Khawaja | 0 Comments
Filed under: