Using System. Collections. Generic



Download 0,84 Mb.
Sana15.07.2022
Hajmi0,84 Mb.
#802656
Bog'liq
Algoritmik tillar


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;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;
using System.Text.RegularExpressions;

namespace WindowsFormsApplication10


{
public partial class Form1 : Form
{
private SqlConnection sqlConnection = null;
DataSet dataSet = null;
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)


{
sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["TestDB"].ConnectionString);
sqlConnection.Open();
if (sqlConnection.State == ConnectionState.Open)
{
MessageBox.Show("Ulandi");
}
}

private void button1_Click(object sender, EventArgs e)


{
insert(textBox1.Text, textBox2.Text, textBox3.Text, textBox4.Text);
}

private void insert(string nomi, string qavat, string telefon, string boshliq)


{
SqlCommand sqlCommand = new SqlCommand("INSERT INTO [bolimlar] (nomi,qavat,telefon,boshliq) VALUES (@nomi,@qavat,@telefon,@boshliq)", sqlConnection);
sqlCommand.Parameters.AddWithValue("nomi", nomi);
sqlCommand.Parameters.AddWithValue("qavat", qavat);
sqlCommand.Parameters.AddWithValue("telefon", telefon);
sqlCommand.Parameters.AddWithValue("boshliq", boshliq);
MessageBox.Show(sqlCommand.ExecuteNonQuery().ToString());
}
private void funk(string query)
{
try
{
dataSet = new DataSet();
SqlDataAdapter dataAdapter = new SqlDataAdapter(query, sqlConnection);
dataAdapter.Fill(dataSet);
dataGridView1.DataSource = dataSet.Tables[0];
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button2_Click(object sender, EventArgs e)
{
int rowindex = dataGridView1.CurrentCell.RowIndex;

funk("DELETE FROM bolimlar where id=" + dataGridView1.Rows[rowindex].Cells[0].Value.ToString());


funk("SELECT * FROM bolimlar");


}

private void button3_Click(object sender, EventArgs e)


{
funk("SELECT * FROM bolimlar");
}

int rowId;


private void dataGridView1_Click(object sender, EventArgs e)
{
int rowindex = dataGridView1.CurrentCell.RowIndex;
rowId = Convert.ToInt32(dataGridView1.Rows[rowindex].Cells[0].Value);
textBox5.Text = dataGridView1.Rows[rowindex].Cells[1].Value.ToString();
textBox6.Text = dataGridView1.Rows[rowindex].Cells[2].Value.ToString();
textBox7.Text = dataGridView1.Rows[rowindex].Cells[3].Value.ToString();
textBox8.Text = dataGridView1.Rows[rowindex].Cells[4].Value.ToString();
}

private void button4_Click(object sender, EventArgs e)


{
SqlCommand sqlCommand = new SqlCommand("UPDATE [bolimlar] SET nomi=@nomi, qavat=@qavat, telefon=@telefon, boshliq=@boshliq WHERE id="+rowId, sqlConnection);
sqlCommand.Parameters.AddWithValue("nomi", textBox5.Text);
sqlCommand.Parameters.AddWithValue("qavat", textBox6.Text);
sqlCommand.Parameters.AddWithValue("telefon", textBox7.Text);
sqlCommand.Parameters.AddWithValue("boshliq", textBox8.Text);
MessageBox.Show(sqlCommand.ExecuteNonQuery().ToString());
MessageBox.Show(sqlCommand.CommandText);
funk("SELECT * FROM bolimlar");
}
}
}
Download 0,84 Mb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish