0% found this document useful (0 votes)
15 views

C#Ref

Uploaded by

sm2nict
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

C#Ref

Uploaded by

sm2nict
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

using System.Data.

OleDb;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace newdepot
{
public partial class frmLogin : Form
{
String constr = null;

public frmLogin()
{
InitializeComponent();
}

private void button7_Click(object sender, EventArgs e)


{
Application.Exit();
}

private void frmLogin_Load(object sender, EventArgs e)


{

constr = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security


Info=False;Initial Catalog=dsnname;Data Source=DELL\\SQLEXPRESS";

Login Button Code


~~~~~~~~~~~~~~~~~~~~
if (txtadmpass.Text.Trim().Equals(""))
{
MessageBox.Show("Please Enter PassWord\n");
txtupass.Focus();
return;
}

String sql = "select * from admininfo where password= '" + txtadmpass.Text + "'";

OleDbConnection con = new OleDbConnection();


con.ConnectionString = constr;
OleDbCommand cmd = new OleDbCommand(sql, con);

OleDbDataReader Reader = null;

try
{
con.Open();
Reader = cmd.ExecuteReader();
if (Reader.Read() == true)
{
Form2 ob=new Form2();
ob.show();

}
else
MessageBox.Show("Invalid User");

}
catch (Exception ee)
{
MessageBox.Show("Error.." +ee.Message);
}

//Insert Code

Constr decn & initialization

if (comboBox1.Text.Equals("") || textBox2.Text.Equals("") )
{
MessageBox.Show("You are missing information");
textBox2.Focus();
return;
}

String sql = "insert into tnlname values (" + textBox2.Text + ",'" comboBox3.Text
+ "')";

OleDbConnection con = new OleDbConnection();


con.ConnectionString = constr;
OleDbCommand cmd = new OleDbCommand(sql, con);

int i;
try
{
con.Open();
i = cmd.ExecuteNonQuery();
MessageBox.Show("inserted");
}
catch (Exception ee) {
MessageBox.Show(ee.Message.ToString ());
}

~~~~~~~~~~~~~~~~~~
//Search Code
~~~~~~~~~~~~~~~~~~
String sql = "select * from tbl where pname='" + txtpname.Text.ToUpper () + "'";

OleDbConnection con = new OleDbConnection();


con.ConnectionString = constr;
OleDbCommand cmd = new OleDbCommand(sql, con);
OleDbDataReader Reader = null;

try
{
con.Open();
Reader = cmd.ExecuteReader();
Reader.Read();

txtdeptname.Text = Reader.GetString(1);
txtmgrname.Text = Reader.GetString(2);
Button5.Enabled = true; //update
Button6.Enabled = true; //delete

}
catch (Exception ee)
{
MessageBox.Show("Error.." + ee.Message);

##################
private void AutoGen()
{
String sql = "select Br_Code from branch order by Br_Code desc";
OleDbConnection con = new OleDbConnection();
con.ConnectionString = constr;
OleDbCommand cmd = new OleDbCommand(sql, con);
OleDbDataReader Reader = null;

try
{
con.Open();
Reader = cmd.ExecuteReader();

if (Reader.Read())
{
int temp = Reader.GetInt32(0) + 1;
txtbrcode.Text = temp.ToString();
}
else
txtbrcode.Text = "1";

}
catch (Exception ee)
{
MessageBox.Show("Error.." + ee.Message);

insert into branch values


("+Br_Code+",'"+BranchArea+"','"+Manager+"','"+M_mobno+"','"+Police_mobno+"','"User
Name','Password');

You might also like