Vous êtes sur la page 1sur 9

1.

sql connection

SqlConnection con = new SqlConnection("Data Source=BAGYA-


\\SQLEXPRESS;Initial Catalog=BANK;Integrated Security=True");
DataSet ds = new DataSet();

2. insert query

SqlCommand cmd = new SqlCommand("insert into HLTABLE


VALUES(@NAME,@FATHERNAME,@ADRESS,@ESTIMATION,@EMI,@INTERESTRATE,@SUERITY
,@MONTHS,@PHOTO)", con);
cmd.Parameters.AddWithValue("@NAME", TBNAME.Text);

3.connection open and close

con.Open();
cmd.ExecuteNonQuery();
con.Close();
SqlDataAdapter da = new SqlDataAdapter("select *from HLTABLE", con);
con.Open();
da.Fill(ds, "HLTABLE");
dataGridView1.DataSource = ds.Tables["HLTABLE"];
con.Close();

4.interest calculate

double sanctionedamount = Convert.ToDouble(tbsamount.Text);


double INTERESTRATE = Convert.ToDouble(TBINTERESTRATE.Text);
double TOTAL = sanctionedamount + (INTERESTRATE / 100 *
sanctionedamount);
MessageBox.Show(TOTAL.ToString());
tbtotal.Text = Convert.ToString(TOTAL);

5.key press
int isNumber = 0;
e.Handled = !int.TryParse(e.KeyChar.ToString(), out isNumber)

6.char press

Char pressedKey = e.KeyChar;


if (Char.IsLetter(pressedKey) || Char.IsSeparator(pressedKey) ||
Char.IsPunctuation(pressedKey))
{
// Allow input.
e.Handled = false;
}
else
{
// Stop the character from being entered into the
control since not a letter, nor punctuation, nor a space.
e.Handled = true;
}

7.image upload

add
cmd.Parameters.AddWithValue("@PHOTO",ImageData);

OpenFileDialog dlg = new OpenFileDialog();


DialogResult dlgRes = dlg.ShowDialog();
if (dlgRes != DialogResult.Cancel)
{
//Set image in picture box
ImageData.ImageLocation = dlg.FileName;

//Provide file path in txtImagePath text box.


textBox1.Text = dlg.FileName;

}
}

byte[] ReadFile(string sPath)


{

//Initialize byte array with a null value initially.


byte[] data1 = null;
try
{

//Use FileInfo object to get file size.


FileInfo fInfo = new FileInfo(sPath);
long numBytes = fInfo.Length;

//Open FileStream to read file


FileStream fStream = new FileStream(sPath,
FileMode.Open, FileAccess.Read);

//Use BinaryReader to read file stream into byte array.


BinaryReader br = new BinaryReader(fStream);

//When you use BinaryReader, you need to supply number


of bytes to read from file.
//In this case we want to read entire file. So supplying
total number of bytes.
data1 = br.ReadBytes((int)numBytes);

}
//catch (ArgumentException argumentexception)
catch (Exception ex)
{
MessageBox.Show("Photo Field Cannot Be Empty.Please
Upload Your Photo", "Warning", MessageBoxButtons.OK,
MessageBoxIcon.Stop);
}
return data1;

and pass this in button or before inserting

byte[] imageData = ReadFile(textBox1.Text);

8.emi calculator

double a = Convert.ToDouble(textBox1.Text);
double b = Convert.ToDouble(textBox2.Text);
double c = Convert.ToDouble(textBox3.Text);
double TOTAL = a + (c / 100 * a);
double t = b * (c / 100 * a);
double d = TOTAL / b;
double f = 12 * (c / 100 * a);
textBox4.Text = Convert.ToString(d);
textBox5.Text = Convert.ToString(TOTAL);
textBox10.Text = Convert.ToString(t);
textBox11.Text = Convert.ToString(f);

9.radio button

string gender = null;

if (RBMALE.Checked == true)
{
gender = "MALE";
}
else if (RBFEMALE.Checked == true)
{
gender = "FEMALE";
}
Add
cmd.Parameters.AddWithValue("@GENDER", gender);

10.date time

DateTime dt = Convert.ToDateTime(dateTimePicker1.Text);
(object creation)
add
cmd.Parameters.AddWithValue("@DATAOFBIRTH", dt);

11.digits accept

Regex rg = new Regex("[^0-9]");


if (rg.IsMatch(TBMOBILENO.Text.Trim()))
{
}
12.refresh

private void refresh()


{
SqlDataAdapter da = new SqlDataAdapter("select *from ACTABLE", con);
con.Open();
da.Fill(ds, "ACTABLE");
dataGridView1.DataSource = ds.Tables["ACTABLE"];
con.Close();
}
Add refresh in connection open automatically create one stub.same
process of validation also and also select one error provider in form
design.

12.search

private void check_Click(object sender, EventArgs e)


{
try
{
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("select * from ACTABLE
where SUERITY='" + TBSUERITY.Text + "'", con);
con.Open();
da.Fill(ds, "ACTABLE");
dataGridView1.DataSource = ds.Tables["ACTABLE"];
con.Close();
}
catch (Exception ex)
{
}
}

13.datagrid

SqlDataAdapter da = new SqlDataAdapter("select *from table_3", con);


con.Open();
da.Fill(ds, "table_3");
dataGridView1.DataSource = ds.Tables["table_3"];
con.Close();

14.total

DataSet ds = new DataSet();


SqlDataAdapter da = new SqlDataAdapter("Select SUM(AMOUNT) FROM CRTABLE
WHERE TOTAL=TBTOTAL", con);
con.Open();
da.Fill(ds, "table_3");
dataGridView1.DataSource = ds.Tables["table_3"];
con.Close();

15.total all row values


try
{
int count = 0;
SqlCommand cmd = new SqlCommand("SELECT SUM(AMOUNT) FROM CRTABLE
where ACCNO='"+TBACCNO.Text.Trim()+"'", con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
count = dr.GetInt32(0);
}
TBTOTAL.Text = Convert.ToString(count);
con.Close();

16.subract and display in balance button

double balance,a;
double CREDIT = Convert.ToDouble(TBTOTAL.Text);
double DEBIT = Convert.ToDouble(TBTOTAL1.Text);
balance = CREDIT - DEBIT;
tbbalance.Text = Convert.ToString(balance);

17.ckeck

DataSet ds = new DataSet();


SqlDataAdapter da = new SqlDataAdapter("select *from ACTABLE where
ACCNO='"+TBACCNO.Text+"'", con);
con.Open();
da.Fill(ds, "ACTABLE");
if(MessageBox.Show("already a member","sure",MessageBoxButtons.OKCancel)
== DialogResult.OK)
{

}
else
{
account ac = new account();
ac.Show();
}
dataGridView1.DataSource = ds.Tables["ACTABLE"];
con.Close();

18.email validation

public bool validation2()


{

if (textBox1.Text == "")
{
errorProvider1.SetError(textBox1, "invalid");
return false;
}
else
{
errorProvider1.SetError(textBox1, "");
return true;
}

private void textBox1_validated(object sender, EventArgs e)


{

if (ValidEmail(textBox1.Text))
{
errorProvider1.SetError(textBox1, "");
}
else
{
errorProvider1.SetError(textBox1, "Error");
}
}

private bool ValidEmail(string EMAIL)


{
//string str = @"^([a-zA-Z0-9_\-\.]+)@([a-z]+).([a-z])$";
string str = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
@"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
@".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";

Regex re = new Regex(str);


if (re.IsMatch(EMAIL))
return (true);

else
MessageBox.Show("invalid");
return (false);

}
}

19.number validation

private bool numberValid(string num)


{
char m = 'f';
if (num != "")
{
string mobile = num;

string strRegex = "^([^-.@#$%&*!,a-zA-Z;:])[0-9]+$";


Regex re = new Regex(strRegex);
if (!(re.IsMatch(mobile)))
{

return false;
}
else
{

return true;
}

}
else
{

return true;
}
}

20.textbox validation

private void textBox5_Validated(object sender, EventArgs e)


{
if (numberValid(textBox5.Text))
{
errorProvider1.SetError(textBox5, "");
}
else
{
errorProvider1.SetError(textBox5, "Error");
}
}

21.delete

SqlCommand cmd = new SqlCommand("delete from staff where name=@name and id=@id",
con);
cmd.Parameters.AddWithValue("@name", textBox1.Text);
cmd.Parameters.AddWithValue("@id", textBox2.Text);

22.login validation

if(Validation())
{
if(textBox1.Text=="krishna" &&
textBox2.Text=="krishna")
{
empdisplayrorm frm=new empdisplayrorm();
frm.Show();
this.Hide();
}
else
{
label3.Visible=true;

}
}

23.validation

private bool Validation()


{

if (textBox1.Text=="")
{
errorProvider1.SetError(textBox1, "invalid");
return false;
}
else
{
errorProvider1.SetError(textBox1, "");
}

if (textBox1.Text=="")
{
errorProvider1.SetError(textBox1, "invalid");
return false;
}
else
{
errorProvider1.SetError(textBox1, "");
}
return true;
}

return true;
}

24.clear
Tbname.text=””

24.timer

{
DateTime t = DateTime.Now;
SqlCommand cmd = new SqlCommand("insert into table_1
values(@name,@logintime)",con);
cmd.Parameters.AddWithValue("@name",textBox1.Text);
cmd.Parameters.AddWithValue("@logintime",t);
//textBox2.Text = Convert.ToString(t);
con.Open();
cmd.ExecuteNonQuery();
MessageBox.Show("succed");
textBox2.Text = Convert.ToString(t);
con.Close();
}
And datatype dati time and add timer to form design

25.update

SqlCommand cmd = new SqlCommand("Update table_1 set name='" +


textBox3.Text.Trim() + "' where name='" + textBox1.Text.Trim() + "'",
con);
con.Open();
cmd.ExecuteNonQuery();
MessageBox.Show("succed");
Con.close();

29.to fix length of number

if (textBox1.Text.Length < 10 )
{
MessageBox.Show("please enter minimum 10 digits");
return false;
}
else
{
return true;
}

30.binding

SqlConnection con = new SqlConnection("Data


Source=BAGYA-\\SQLEXPRESS;Initial Catalog=phone;Integrated
Security=True");

DataSet ds = new DataSet();


SqlDataAdapter da = new SqlDataAdapter("select * from
table_1 where id='" + textBox2.Text.Trim() + "'", con);
con.Open();
da.Fill(ds, "table_1");
textBox1.DataBindings.Add("text", ds, "table_1.num");

Vous aimerez peut-être aussi