Najam Sikander Awan

logs of my work and digital life

Follow me on TwitterRSS Feeds

  • Home
  • About Me

Random rows selection from a database table

Jan 29th

Posted by Najam Sikander Awan in Devlopment

No comments

hi everyone,

today I discovered a nice tip from a blog I never knew selecting random rows were that easy with sqlserver 2000 and above. I have a country table that has four countries and from 4 I am selecting random 2.

SELECT TOP 2 * FROM country ORDER By NEWID()
select * from country

First Result

3           SaudiArabia
4           France

Second Result

1           UAE
4           France

Third Result

1           UAE
3           SaudiArabia

All Countries

1           UAE
2           Pakistan
3           SaudiArabia
4           France

Amazing right??

Database, Sql

cbhtrade.com launched

Jan 27th

Posted by Najam Sikander Awan in Projects

No comments

hi guys

After playing with wordpress we decided to make a small static website using wordpress 2.7. Please check it out at http://cbhtrade.com/cbh/

Wordpress

Tdfsolutions.com

Jan 27th

Posted by Najam Sikander Awan in Projects

No comments

hi guys

well I have been learning html and css and my company let me do some slicing for them so here is my first offical html/css project please visit http://www.tdfsolutions.com .

Wordpress

WordPress wamp and permalinks

Jan 27th

Posted by Najam Sikander Awan in I Want To Know?

2 comments

hi everyone

I am posting after a long time guess I was super busy :) well first things first I have installed wordpress 2.7 on my hosting and imported all the data from my blog running at http://najam.wordpress.com.

Now a days I am busy with developing themes with wordpress and since I am stuck with windows wamp is a choice for me. One problem I run into is if I try to put custom structure for my permalinks to have more seo friendly blog it fails to show the post or page :( . Anyone know whats the problem? And even if I do this for this blog you reading it would fail to show the page/post that includes the front page.

Wordpress

Google Chrome Bookmarks?

Sep 27th

Posted by Najam Sikander Awan in I Want To Know?

2 comments

hi friends 

You know google chrome is out and everyone was so excited about that including me as a very passionate user i tried to do all of the things now in chrome i have imported my firefox settings (bookmarks) into chrome. All bookmarks are showing good I liked that but shortly I needed to perform a simple task in chrome that is “searching for a bookmarked site among all the bookmarks i have” and till now i don’t know how to search for my bookmark in mighty chrome. 

So if anyone of you know how to seach bookmarks in chrome please let me know. And one more thing what about tags how can I tag my pages?

chrome

Sql Data Srouce Control Updating Data From Database

Jul 17th

Posted by Najam Sikander Awan in Asp.net

No comments

hey guyz finally we have to learn how to update our tables in database so only for you guys here is my sample code

string giftId = GridView1.SelectedRow.Cells[0].Text.ToString(); //getting an id
SqlDataSource myDbSource = new SqlDataSource();
myDbSource.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
//myDbSource.InsertCommand = “update gifts set giftActivate=1 where giftId=” + Entrydate + “)”;
myDbSource.UpdateCommand = “update gifts set giftActivate=’1′ where giftId=” + giftId;
myDbSource.ProviderName = “System.Data.SqlClient”;
myDbSource.Update();

Well this code set giftActive flag to 1 for all the rows matched with giftid value.

asp.net, C#, Data Access, web development

Sql Data Srouce Control Deleting Data From Database

Jul 17th

Posted by Najam Sikander Awan in Asp.net

1 comment

Hey guyz today i will show you how to fire delete query by using our beloved control sqldatasource.

Here is the code

SqlDataSource myDbSource22 = new SqlDataSource();
myDbSource22.ConnectionString = ConfigurationManager.ConnectionStrings["lalConnectionString"].ConnectionString;
myDbSource22.ProviderName = “System.Data.SqlClient”;
myDbSource22.DeleteCommand = “delete from ProductsGroups where pid = ” + productId;
myDbSource22.Delete();

All it does it deletes all the rows for a given productID from table productgroups. Simple right ;)

asp.net, C#, Data Access, web development

Sql Data Srouce Control Inserting Data Into Database

Jul 17th

Posted by Najam Sikander Awan in Asp.net

1 comment

hey guyz how are you ??

Me back with my sqldatasource  series. Today i will show you how to fire insert query using sqldatasource control into code behind i am using c#.

Below is the sample code UserID is the parameter passing into a function as an argument.

DateTime Entrydate = DateTime.Today;
SqlDataSource myDbSource = new SqlDataSource();
myDbSource.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
myDbSource.InsertCommand = “insert into tbl_invoices (user,Entrydate) values (” + UserID + “,’” + Entrydate + “‘)”;
myDbSource.ProviderName = “System.Data.SqlClient”;
myDbSource.Insert();

myDbSource.SelectCommand = “SELECT IDENT_CURRENT(‘tbl_invoices’)”;
DataView dv = (DataView)myDbSource.Select(new DataSourceSelectArguments());
DataTable dt = dv.Table;
string invNumber = dt.Rows[0][0].ToString();
return invNumber.ToString();
//return string.Empty;

Code above is very simple what it does simple take UserID as an argument and then insert a new record into tbl_invoices table and then after it i am firing a select statement that returns the latest ID into tbl_invoices table. SELECT IDENT_CURRENT(‘table name’) return the id of the last record inserted into the table.

Happy coding bye

asp.net, C#, Data Access, web development

Sql Data Srouce Control Fetch data from database

Jul 16th

Posted by Najam Sikander Awan in Asp.net

No comments

Hi in asp.net 2.0 this new datasource control has been added and i liked it alot and i used it on many places so i thought it would be nice if I share my knowledge with all my readers so first of all i would just like to show you how to retrieve some data from your database into C# code behind file.

string userID = string.Empty;

string UserName=”najam”;
SqlDataSource myDbSource = new SqlDataSource();
myDbSource.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
myDbSource.SelectCommand = “select userId from Users where userName=’” + UserName + “‘”;
myDbSource.ProviderName = “System.Data.SqlClient”;
DataView dv = (DataView)myDbSource.Select(new DataSourceSelectArguments());
DataTable dt = dv.Table;
if (dt.Rows.Count > 0)
{
userID = dt.Rows[0][0].ToString();
}

Above code will return user id if username supplied. You will see no data adapters or command object.

If you like instead of creating sql datasrouce control in code behind just drag and drop it onto ur aspx page and then in your code behind reference it that will shorten the line of code for fetching data from your database.

asp.net

Finally my Ms is completed

Jul 16th

Posted by Najam Sikander Awan in Today

No comments

Ummm whats new in my life?

Well finally my Ms in telecom is completed all courses are clear and i am fleeing like a free bird. Tension free consitration on my job no more travling in triangle from home to office and then from there to university.

Hopefully now i will get some time to write for my blog. If anyone still reading please keep reading

News
«12345»...Last »
  • My latest tweets

    Loading tweets...
    Follow me on Twitter!
    • Recent comments
    • Popular posts
    • Archives
    • Tags
    • Categories
    • Ajax (2)
    • Articles (1)
    • Asp.net (11)
    • C# (9)
    • Concepts (5)
    • Counter Strike (1)
    • Designing (2)
    • Devlopment (10)
    • Firefox (7)
    • git (2)
    • I Want To Know? (3)
    • Javascript (3)
    • Jquery (4)
    • linq (2)
    • Linux (8)
    • My Stuff (1)
    • Photoshop (1)
    • Projects (3)
    • Sql (1)
    • Telecommunication (2)
    • Tips & Tricks (7)
    • Today (33)
    • ToDo (1)
    • Troubles (1)
    • Uncategorized (38)
    • Wordpress (3)
    .net acer Ajax announcements asp.net audio driver boot loader Browsers Browsing C# chrome Concepts Counter Strike Data Access Database development dual boot fedora Firefox game git grub Javascript Jquery linq Linux mac spoofing multimedia News OOP OOPS Project realtek sound card Sql suse Tips Visual Studio vychat web development web services wifi Windows windows xp Wordpress
    • July 2010 (2)
    • January 2010 (1)
    • July 2009 (6)
    • June 2009 (8)
    • February 2009 (3)
    • January 2009 (4)
    • September 2008 (1)
    • July 2008 (6)
    • November 2007 (2)
    • October 2007 (1)
    • September 2007 (2)
    • June 2007 (2)
    • April 2007 (3)
    • March 2007 (3)
    • February 2007 (4)
    • January 2007 (1)
    • December 2006 (3)
    • April 2006 (2)
    • February 2006 (3)
    • January 2006 (2)
    • December 2005 (5)
    • November 2005 (4)
    • Gmail, Msn Live and other invites (27)
    • My Acer Aspire 1642ZNWLCi (15)
    • Real Firefox (7)
    • Msn Messenger Live (6)
    • Vychat alternative for my suse 10.2 laptop (5)
    • Fedora Core6 live-configuring internet by spoofing mac address (4)
    • Who invented CDMA (3)
    • oh God Hd audio driver for linux (3)
    • Read SMTP settings from asp.net web.config (3)
    • Realtek HD sound card working (2)
    • Kaifi: Yest it is :). Great Work Najam....
    • Najam Sikander Awan: @Anthony hi thanks for reading my blog and thanks for commenting and posting solution to our common...
    • Anthony Alexander: If you haven't already solved the problem, I just found the solution myself. open Apache...
    • faheem: http://www.cplug.org/guides/post-install.html
    • admin: thanks dear :)
    • Muhammed Shakhsheer: Hi Najam i have Acer aspire 1642ZNWLCi, which is the same you do, i have a problem that i dont...
    • John chaffee: Oh Man...thank you so much for posting! I have been working non this for about 4 hours. I...
    • Imran Agha: Hi Najam/Everyone, I have a Acer 1642 Laptop. Unfortunately its motherboard has gone bust and I...
  • User Login






    • Lost your password?
    • My latest tweets

      Loading tweets...
      Follow me on Twitter!
Mystique theme by digitalnature | Powered by WordPress
RSS Feeds XHTML 1.1 Top