Saturday, January 27, 2007

Populating data into DataGridview of Windows Forms in .NET 2.0

Populating data into DataGridview of Windows Forms in .NET 2.0
////string select = "select Meaning,Examples from "+tablename+" where Word="+"'"+Searchword+"'";
////SqlConnection conn = new SqlConnection(ConnString);
////conn.Open();
////SqlCommand cmd1 = new SqlCommand(select,conn);

//SqlDataAdapter adap = new SqlDataAdapter(cmd1);
//DataTable dt = new DataTable();
//dt.Locale = System.Globalization.CultureInfo.InvariantCulture;
//adap.Fill(dt);
//bndSource.DataSource = dt;
//dgvSrchWord.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
//dgvSrchWord.ReadOnly = true;
//dgvSrchWord.DataSource = bndSource;

//conn.Close();

Usage of Sql Reader in C#

Connection string is been added n the App setting of app.config file
//string select = "select Meaning,Examples from "+tablename+" where Word="+"'"+Searchword+"'";
//SqlConnection conn = new SqlConnection(ConnString);
//conn.Open();
//SqlCommand cmd1 = new SqlCommand(select,conn);
////SqlDataReader dr = cmd1.ExecuteReader();
////while (dr.Read())
////{
//// string value = dr[0].ToString();
//// //txtMeaning.Text = dr[1].ToString();
//// MessageBox.Show(value);

////}

Thursday, January 18, 2007

To get single character from String in C#

//To get single character from String in C#
// byte[] m = Encoding.Unicode.GetBytes("chetan@123");
//
// string n = Encoding.Unicode.GetString(m, 0,2);
// Console.WriteLine(n);

Use of Streamwriter/Reader and Arraylist in C#

"//Use of Streamwriter/Reader and Arraylist in C#
StreamWriter exportfile = new StreamWriter("C:\\temp\\ExportFile.txt");
//
//
ArrayList mylist = new ArrayList();

StreamReader sr = new StreamReader("C:\\temp\\shadow");
string line;
while((line=sr.ReadLine())!= null)
{
mylist.Add(line);
}


int count = mylist.Count;

string[] userarray;
ArrayList username = new ArrayList();


for(int i=0; i {
string users = mylist[i].ToString();
userarray= users.Split(Convert.ToChar(":"));
username.Add(userarray[0].ToString());

}
for(int j=0; j {
exportfile.WriteLine("objType:person");
exportfile.WriteLine("givenName:" + username[j].ToString());
exportfile.WriteLine("name:" + username[j].ToString());
exportfile.WriteLine("userid:" + username[j].ToString());
exportfile.WriteLine("displayName:" + username[j].ToString());
exportfile.WriteLine();

}
// Console.ReadLine();
exportfile.Close(); "

Creating Ascii text file from C#

//Creating Ascii text file from C#
// byte[] messagebyte = Encoding.ASCII.GetBytes("naviputti@321");
// FileStream fwrite = new FileStream("C:\\temp\\na.txt",FileMode.Create);
//
// //fwrite.WriteByte((byte)messagebyte.Length);
// fwrite.Write(messagebyte,0,messagebyte.Length);
// fwrite.Close();