Code Snippets

Dislay Data on datagrid in csharp

Just post simple code. Give a feedback if it helps u :) (View Snippet)
  1. using System;
  2. using System.Collection.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Data.SqlClient;
  9.  
  10. namespace WindowsApplication1
  11. {
  12. public partial class Form1 : Form
  13. {
  14. public Form1()
  15. {
  16. InitializeComponent();
  17. }
  18.  
  19. private void cmdtam_Klik(object sender, EventArgs e)
  20. {
  21. string cstr;
  22. cstr = "data source=jery;initial catalog=latihan;uid=sa;pwd=sri";
  23. SqlConnection con1 = new SqlConnection(cstr);
  24. con1.Open();
  25. SqlCommand com1 = new SqlCommand();
  26. com1.Connection = con1;
  27. com1.CommandType = CommandType.Text;
  28. com1.CommandText = "select * from customer"
  29. DataSet ds1 = new DataSet();
  30. SqlDataAdapter adp1 = new SqlDataAdapter(com1);
  31. adp1.Fill(ds1,"customer");
  32. grd1.DataMember = "customer";
  33. con1.Close();
  34. }
  35. }
  36. }

Another use of substr in cplusplus

Frequently, you may need to isolate words in a phrase. In this example, we'll use substr to carry out this task. (View Snippet)
  1. string phrase = "Now is the oppurtunity to claim money";
  2. string word;
  3. int i, space;
  4. phrase+=" ";//add space to end of phrase
  5. while(phrase.length()>0)
  6. {
  7. space = phrase.find();//find position of the first space in phrase
  8. word = phrase.substr(0,space);
  9. //process word here and then go to next word
  10. cout<<word<<endl;
  11. phrase = phrase.substr(space+1);//create new phrase with first word chopped off
  12. }//end while phrase
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 3:31 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC