Wednesday, September 19, 2012
Monday, July 9, 2012
Lessons : C# with SQL Server
Retrieve data to dataGridview
SqlDataAdapter da = new SqlDataAdapter(" sql quary", con);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
Retrieve data to combo box
SqlDataAdapter da = new SqlDataAdapter(" sql quary ", con);
con.Open();
DataTable dt = new DataTable();
da.Fill(dt);
txtcrs.DataSource = dt;
txtcrs.ValueMember = "crs_name";
con.Close();
Insert ,Update, Remove
SqlCommand cmd = new SqlCommand("sql quary", con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
SqlData Reader
con.Open();
SqlCommand cmd = new SqlCommand("sql quary", con);
SqlDataReader dr = cmd.ExecuteReader();
dr.Read();
txypwd.Text = dr[0].ToString();
dr.Close();
con.Close();
Play Sound
import this - using System.Media;
SoundPlayer sp2 = new SoundPlayer("C:\\sounds\\access_denied.wav");
timer2.Start();
Check Connection State
if (con.State == ConnectionState.Open)
con.Close();
Connection Dbcon class Method
public static SqlConnection getConnection()
{
return new SqlConnection("Data Source=.;Initial Catalog=SAS;Integrated Security=True");
}
and import this to your windows form
SqlConnection con = DbCon.getConnection();
Read Image from database
SqlDataAdapter adp = new SqlDataAdapter("sp_SearchStImage '" + bn + "'", con);
DataTable dt = new DataTable();
adp.Fill(dt);
pictureBox1.Image = coverter.byteArrayToImage((byte[])dt.Rows[0][0]);
select datagrid view first column and current row
dataGridView1.CurrentRow.Cells[0].Value.ToString()
Complete Crystal Reports tutorial A to Z with C#
csharp.net-informations.com
SqlDataAdapter da = new SqlDataAdapter(" sql quary", con);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
Retrieve data to combo box
SqlDataAdapter da = new SqlDataAdapter(" sql quary ", con);
con.Open();
DataTable dt = new DataTable();
da.Fill(dt);
txtcrs.DataSource = dt;
txtcrs.ValueMember = "crs_name";
con.Close();
Insert ,Update, Remove
SqlCommand cmd = new SqlCommand("sql quary", con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
SqlData Reader
con.Open();
SqlCommand cmd = new SqlCommand("sql quary", con);
SqlDataReader dr = cmd.ExecuteReader();
dr.Read();
txypwd.Text = dr[0].ToString();
dr.Close();
con.Close();
Play Sound
import this - using System.Media;
SoundPlayer sp2 = new SoundPlayer("C:\\sounds\\access_denied.wav");
timer2.Start();
Check Connection State
if (con.State == ConnectionState.Open)
con.Close();
Connection Dbcon class Method
public static SqlConnection getConnection()
{
return new SqlConnection("Data Source=.;Initial Catalog=SAS;Integrated Security=True");
}
and import this to your windows form
SqlConnection con = DbCon.getConnection();
Read Image from database
SqlDataAdapter adp = new SqlDataAdapter("sp_SearchStImage '" + bn + "'", con);
DataTable dt = new DataTable();
adp.Fill(dt);
pictureBox1.Image = coverter.byteArrayToImage((byte[])dt.Rows[0][0]);
select datagrid view first column and current row
dataGridView1.CurrentRow.Cells[0].Value.ToString()
Complete Crystal Reports tutorial A to Z with C#
csharp.net-informations.com