Code Snippets
Dislay Data on datagrid in csharp
Just post simple code. Give a feedback if it helps u :) (View Snippet)
using System; using System.Collection.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void cmdtam_Klik(object sender, EventArgs e) { string cstr; cstr = "data source=jery;initial catalog=latihan;uid=sa;pwd=sri"; SqlConnection con1 = new SqlConnection(cstr); con1.Open(); SqlCommand com1 = new SqlCommand(); com1.Connection = con1; com1.CommandType = CommandType.Text; com1.CommandText = "select * from customer" DataSet ds1 = new DataSet(); SqlDataAdapter adp1 = new SqlDataAdapter(com1); adp1.Fill(ds1,"customer"); grd1.DataMember = "customer"; con1.Close(); } } }
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)
string phrase = "Now is the oppurtunity to claim money"; string word; int i, space; phrase+=" ";//add space to end of phrase while(phrase.length()>0) { space = phrase.find();//find position of the first space in phrase word = phrase.substr(0,space); //process word here and then go to next word cout<<word<<endl; phrase = phrase.substr(space+1);//create new phrase with first word chopped off }//end while phrase


