simple example ado.net

Monday, May 24, 2010

ADO.Net

---------------------SqlQuerys------------------------------------------
Select * from TableName or ViewName


Insert Into TableName
(colname,colname)
values
('calvalue','colvalue')


UPdate TableName
set ColumnName='Value', ColumnName='Value'


---------------------------------------ConnectionString---------
Data Source=myServerAddress;Initial Catalog=myDataBase;User
Id=myUsername;Password=myPassword;

SqlConnection cn = new SqlConnection("Data
Source=-SERVER\\express;Initial Catalog=GIS;Integrated Security=True");;


----------------------------------Disconnected
Ado.net-------------------------------------


xxxConnection cn = new xxxConnection();
xxxDataAdapter da = new xxxDataAdapter("Select * from",cn);
DataSet ds = new DataSet();
da.Fill(ds);
---------------- Data will be loaded in Dataset(ds) NOw you can change data--
---------------------After Change Data in Ds to save data In database -----
ds.AcceptChanges();
da.Update(ds);

----------------------------------connected
Ado.net-------------------------------------



xxxConnection cn = new xxxConnection();

xxxCommand cmd = new xxxCommand("SqlQuery",cn);

try
{
//Select Command
SqlCommand cmd = new SqlCommand("Select * From app_users", cn);
//Check Connection State and Open it
if (cn.State != System.Data.ConnectionState.Open) { cn.Open(); }
//Executereader to fatch data;
SqlDataReader reader = cmd.ExecuteReader();
//Read Data Till Last Record from While
while (reader.Read())
{
Console.WriteLine(reader[1].ToString());
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
//last close connectionString
cn.Close();

}
Console.ReadLine();

share this post
Share to Facebook Share to Twitter Share to Google+ Share to Stumble Upon Share to Evernote Share to Blogger Share to Email Share to Yahoo Messenger More...

2 comments:

Business Circle said...

Sir Usama Wahab khan,microsoft teaching partner its my pleasure to write some words about my teacher.He provide us up-to-date information about Microsoft Technologies.Thank you so much.Please keep the community update to know about latest Microsoft technologies.

Regards,
Global SEO Consultants

Usama Wahab Khan said...

thanks you