You are on page 1of 2

Database table

create database Retail;


create table Products(
id int identity primary key,
Barcode nvarchar(30) not null,
Productsname nvarchar(30),
purty int, experitiondate
date, chaseprice int,
sellprtice int, );
create table Soldproducts(
productid int identity primary key,
Barcode nvarchar(30) not null, qty
int, dateforsale date, sellprice
int, ); using System; using
System.Collections.Generic; using
System.ComponentModel; using
System.Data; using System.Drawing;
using System.Linq; using
System.Text; using
System.Threading.Tasks; using
System.Windows.Forms; using
System.Data.SqlClient; namespace
WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{

//prsyare 4
private void button_TextChanged(object sender, EventArgs e)
{

try{
connection con =new connection();
con.dbconect();
SqlCommand cmd=new SqlCommand ("insert into
SoldProducts(productsid,Barcode,qty,dateofsale,sellprice)values(@id,@barcode,@Qty,@date,@
sell)",connection.conn);
cmd.Parameters .AddWithValue("@id",Convert.ToInt16 (textBox1.Text) );
cmd.Parameters .AddWithValue("@barcode",textBox2.Text );

cmd.Parameters .AddWithValue("@Qty",Convert.ToInt16 (textBox3.Text) );

cmd.Parameters .AddWithValue("@date",textBox4.Text );
cmd.Parameters .AddWithValue("@sell",Convert.ToInt16 (textBox5.Text) );
cmd.ExecuteNonQuery(); con.conClose();
}}

Catch(exception ex){
MessageBox.Show(ex.Message);
}

//prsyare 1

private void Button1_TextChanged(object sender, EventArgs e)


try{
connection cob=new connection(); con.conClose();
String username;
SqlCommand cmd=new SqlCommand ("Select * from Login Where
username=@user",connection.conn);
cmd.Parameters .AddWithValue("@user",textBox1 .Text );
SqlDataReader rdr=cmd.ExecuteReader();
if(rdr.HasRows){ rdr.Read();
username=rdr["userrname"].ToString ();
}

}
}
}

You might also like