Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

C#Ref

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 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