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.OleDb;
namespace WindowsFormsApplication56
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
OleDbConnection con = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=okul.mdb");
int i = 0;
private void button3_Click(object sender, EventArgs e)
{
con.Open();
listBox1.Items.Clear();
OleDbDataAdapter da = new OleDbDataAdapter("select * from sinif", con);
DataSet ds = new DataSet();
da.Fill(ds, "elma");
int a = ds.Tables[0].Rows.Count;
for (int j = 0; j < a; j++)
{
listBox1.Items.Add(ds.Tables[0].Rows[j][0].ToString() + ")" + ds.Tables[0].Rows[j][1].ToString() + " " + ds.Tables[0].Rows[j][2].ToString());
}
con.Close();
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
i = listBox1.SelectedIndex;
con.Open();
OleDbDataAdapter da = new OleDbDataAdapter("select * from sinif", con);
DataSet ds = new DataSet();
da.Fill(ds, "elma");
label1.Visible = true;
label1.Text = ds.Tables[0].Rows[i][0].ToString();
textBox1.Text = ds.Tables[0].Rows[i][1].ToString();
textBox2.Text = ds.Tables[0].Rows[i][2].ToString();
con.Close();
}
private void button2_Click(object sender, EventArgs e)
{
int m = 0;
con.Open();
OleDbDataAdapter da = new OleDbDataAdapter("select * from sinif", con);
DataSet ds = new DataSet();
da.Fill(ds, "elma");
int s = int.Parse(label1.Text);
OleDbCommand cmd = new OleDbCommand("update sinif set okulno='" + textBox1.Text + "',ad='" + textBox2.Text + "' where sn=@kk", con);
cmd.Parameters.AddWithValue("@kk", s);
int a = ds.Tables[0].Rows.Count;
for (int j = 0; j < a; j++)
{
if (textBox1.Text == ds.Tables[0].Rows[j][1].ToString())
{
m = 1;
}
}
if(m==1)
{
MessageBox.Show("Başka okul no giriniz...");
textBox1.Clear();
textBox1.Focus();
}
if(m==0)
{
cmd.ExecuteNonQuery();
}
con.Close();
}
}
}
Hiç yorum yok:
Yorum Gönder