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

Form One:: Using Using Using Using Using Using Using Using Using Using Namespace Public Partial Class New

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

FORM ONE:

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; using System.Data.SqlClient; using System.Collections; namespace data { public partial class Form1 : Form { SqlConnection con = new SqlConnection("Data Source=VISHALPC\\SQLEXPRESS;Initial Catalog=khatri;Integrated Security=True;Pooling=False"); ArrayList list = new ArrayList(); public Form1() { InitializeComponent(); } private void btnSubmit_Click(object sender, EventArgs e) { string _InsertRow = "Insert into data(name,surname,dob,rank,qual,address,state,country,username,password)value s(@name,@surname,@dob,@rank,@qual,@add,@state,@country,@user,@pass)"; SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandType = CommandType.Text; cmd.CommandText = _InsertRow; cmd.Parameters.Add(new SqlParameter("@name", txtName.Text)); cmd.Parameters.Add(new SqlParameter("@surname", txtSurname.Text)); cmd.Parameters.Add(new SqlParameter("@dob", txtDob.Text)); cmd.Parameters.Add(new SqlParameter("@rank", Convert.ToInt32(txtRank.Text))); cmd.Parameters.Add(new SqlParameter("@qual", comboBox1.SelectedItem )); cmd.Parameters.Add(new SqlParameter("@add", txtAdd.Text)); cmd.Parameters.Add(new SqlParameter("@state", txtState.Text)); cmd.Parameters.Add(new SqlParameter("@country", comboBox2.SelectedItem)); cmd.Parameters.Add(new SqlParameter("@user", txtUsername.Text)); cmd.Parameters.Add(new SqlParameter("@pass", txtPassword.Text)); // cmd.Parameters.Add(new SqlParameter("@date", Convert.ToDateTime(System.DateTime.Now).ToShortDateString())); con.Open(); cmd.ExecuteNonQuery(); con.Close(); label11.Visible = true;

MessageBox.Show(label11.Text); Form2 f = new Form2(); f.ShowDialog(); } private void btnReset_Click(object sender, EventArgs e) { txtAdd.Text = ""; txtDob.Text = ""; txtName.Text = ""; txtPassword.Text = ""; txtRank.Text = ""; txtState.Text = ""; txtSurname.Text = ""; txtUsername.Text = ""; } private void btnCheck_Click(object sender, EventArgs e) { con.Open(); SqlDataAdapter da; DataSet ds1= new DataSet(); string sql = "select username from data"; da = new SqlDataAdapter(sql, con); da.Fill(ds1, "order"); DataRow dRow = ds1.Tables["order"].Rows[0]; int count = int.Parse(ds1.Tables["order"].Rows.Count.ToString()); string[] usrname = new string[count]; DataRow[] dr = new DataRow[count]; for (int i = 0; i < count; i++) { dr[i] = ds1.Tables["order"].Rows[i]; usrname[i] = dr[i].ItemArray.GetValue(0).ToString(); list.Add(usrname[i]); } if (list.Contains(txtUsername.Text) == true) { label12.Visible = true; } else { label12.Visible = false; label13.Visible = true; } con.Close(); } private void Form1_Load(object sender, EventArgs e) { } }

FORM TWO:
using using using using using using using using System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Linq; System.Text; System.Windows.Forms;

namespace data { public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void Form2_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'khatriDataSet2.data' table. You can move, or remove it, as needed. this.dataTableAdapter.Fill(this.khatriDataSet2.data); } private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { Form3 f = new Form3(); f.Show(); } } }

FORM THREE:
using using using using using using using using using System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Linq; System.Text; System.Windows.Forms; System.Data.SqlClient;

namespace data { public partial class Form3 : Form { int MaxRow = 0; int ctr = 0; SqlConnection con = new SqlConnection("Data Source=VISHALPC\\SQLEXPRESS;Initial Catalog=khatri;Integrated Security=True;Pooling=False"); SqlCommand cmd = new SqlCommand(); SqlDataAdapter da; DataSet ds = new DataSet(); public Form3() { InitializeComponent(); string str = "select * from data"; con.Open(); da = new SqlDataAdapter(str, con); da.Fill(ds, "table"); con.Close(); MaxRow = ds.Tables["table"].Rows.Count; retreive(); } private void retreive() { DataRow dr = ds.Tables["table"].Rows[ctr]; label9.Text = dr.ItemArray.GetValue(0).ToString(); label10.Text = dr.ItemArray.GetValue(1).ToString(); label11.Text = dr.ItemArray.GetValue(2).ToString(); label12.Text = dr.ItemArray.GetValue(3).ToString(); label13.Text = dr.ItemArray.GetValue(4).ToString(); label14.Text = dr.ItemArray.GetValue(5).ToString(); label15.Text = dr.ItemArray.GetValue(6).ToString(); label16.Text = dr.ItemArray.GetValue(7).ToString(); int pos = ctr; pos++; lblStatus.Text = "Record " + pos + " of " + MaxRow; } private void btnNext_Click(object sender, EventArgs e)

{ if(ctr<(MaxRow-1)) { ctr++; retreive(); } else MessageBox.Show("no more records"); } private void btnPrev_Click(object sender, EventArgs e) { if (ctr > 0) { ctr--; retreive(); } else MessageBox.Show("no more records"); } } }

Database sir example::

using using using using using using using using

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

namespace db_success { public partial class Form1 : Form { public Form1() { InitializeComponent(); } System.Data.SqlClient.SqlConnection con; System.Data.SqlClient.SqlDataAdapter da; DataSet ds1; int MaxRow = 0; int inc = 0; private void Form1_Load(object sender, EventArgs e) { con = new System.Data.SqlClient.SqlConnection(); ds1 = new DataSet(); con.ConnectionString = "Data Source=THESUN-PC\\sqlexpress;Initial Catalog=Northwind;Integrated Security=True"; con.Open(); string sql = "select * from customers"; da = new System.Data.SqlClient.SqlDataAdapter(sql,con); da.Fill(ds1,"cust"); con.Close(); } private void navigateRecords() { DataRow dRow = ds1.Tables["cust"].Rows[inc]; txtcustid.Text = dRow.ItemArray.GetValue(0).ToString(); txtcompname.Text = dRow.ItemArray.GetValue(1).ToString(); int pos = inc; pos++; lbl.Text = "Record " + pos + " of " + MaxRow; } private void btn_next_Click(object sender, EventArgs e) {

if (inc != MaxRow - 1) { inc++; navigateRecords(); } else { MessageBox.Show("No More Records", "Warning"); } } private void btn_prev_Click(object sender, EventArgs e) { if(inc>0) { inc--; navigateRecords(); } else { MessageBox.Show("First Record", "Warning"); } } private void button1_Click(object sender, EventArgs e) { if (inc!=0) { inc=0; navigateRecords(); } } private void button2_Click(object sender, EventArgs e) { if (inc != MaxRow - 1) { inc = MaxRow - 1; ; navigateRecords(); } } private void button7_Click(object sender, EventArgs e) { txtcustid.Clear(); txtcompname.Clear(); butnSave.Enabled = true; } private void butnSave_Click(object sender, EventArgs e) { System.Data.SqlClient.SqlCommandBuilder cb; cb = new System.Data.SqlClient.SqlCommandBuilder(da); DataRow drow = ds1.Tables["cust"].NewRow();

drow[0] = txtcustid.Text; drow[1] = txtcompname.Text; ds1.Tables["cust"].Rows.Add(drow); MaxRow = MaxRow + 1; inc = MaxRow - 1; da.Update(ds1,"cust"); MessageBox.Show("Record Added!"); } private void btn_update_Click(object sender, EventArgs e) { System.Data.SqlClient.SqlCommandBuilder cb; cb = new System.Data.SqlClient.SqlCommandBuilder(da); DataRow drow2 = ds1.Tables["cust"].Rows[inc]; drow2[0] = txtcustid.Text; drow2[1] = txtcompname.Text; da.Update(ds1, "cust"); MessageBox.Show("Record Updated!"); } private void button7_Click_1(object sender, EventArgs e) { MaxRow = ds1.Tables["cust"].Rows.Count; navigateRecords(); } private void button8_Click(object sender, EventArgs e) { txtcustid.Text = " "; txtcompname.Text = " "; MaxRow = 0; } private void btn_delete_Click(object sender, EventArgs e) { System.Data.SqlClient.SqlCommandBuilder cb; cb = new System.Data.SqlClient.SqlCommandBuilder(da); ds1.Tables["cust"].Rows[inc].Delete(); MaxRow--; inc = 0; navigateRecords(); da.Update(ds1, "cust"); MessageBox.Show("Record Deleted!"); } private void label3_Click(object sender, EventArgs e) { } private void btn_search_Click(object sender, EventArgs e) { string search = txt_search.Text;

int results = 0; DataRow[] returnedRows; returnedRows = ds1.Tables["cust"].Select("CustomerID=" + search); results = returnedRows.Length; if (results > 0) { DataRow dr1; dr1 = returnedRows[0]; txtcustid.Text=dr1["CustomerID"].ToString(); txtcompname.Text=dr1["CompanyName"].ToString(); MaxRow = ds1.Tables["cust"].Rows.Count; } else { MessageBox.Show("No such record!"); } } } }

You might also like