15.42-rasm. Komponentani ma’lumotlar bazasi bilan bog‘lash qadamlari
15.43-rasm. Data Source komponentasini sozlash oynasi
15.44-rasm. Data Source komponentasini sozlash oynasida ma’lumotlar bazasini tanlash maydoni
15.45-rasm. Sozlanmalarni saqlash oynasi
|
15.46-rasm. Ma’lumotlar bazasi ob’ektlarini tanlash oynasi
|
15.47-rasm. Kerakli jadvallarni tanlash uchun ketma-ketliklar
|
15.48-rasm. DataGridView komponentasining faollashtirilganlik holati
|
15.49-rasm. Form1 oynasining yangi holati
|
Dasturni ishga tushirib quyidagi oynani hosil qilamiz (15.50-rasm)
15.50-rasm. Ma’lumotlar bazasining Form1 oynasidagi ko‘rinishi
Demak, biz masalining qo‘yilishida keltirib o‘tilgan barcha parametrlarni bajardek va uning tasdiqlarini ko‘rsatib o‘tdek.
C# DASTURINING MYSQL BILAN BOG’LASH ILOVASI
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public string conString = "Data Source=DESKTOP-RE3K95V;Initial Catalog=dekanat;Integrated Security=True";
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(conString);
con.Open();
if (con.State == System.Data.ConnectionState.Open)
{
string m = "INSERT INTO talaba(ID, Name, Age) VALUES('" + txtID.Text.ToString() + "', '" + txtName.Text.ToString() + "', '" + txtAge.Text.ToString() + "')";
SqlCommand k = new SqlCommand(m, con);
k.ExecuteNonQuery();
con.Close();
MessageBox.Show("Amaliyot bajarildi !!!");
}
}
private void button2_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(conString);
con.Open();
if (con.State == System.Data.ConnectionState.Open)
{
string m = "UPDATE Talaba SET Name='"+txtName.Text+"' WHERE ID='"+txtID.Text+"'";
SqlCommand k = new SqlCommand(m, con);
k.ExecuteNonQuery();
con.Close();
MessageBox.Show("O'zgartirish amalga oshirildi !!!");
}
}
private void button3_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(conString);
con.Open();
if (con.State == System.Data.ConnectionState.Open)
{
string m = "DELETE FROM Talaba WHERE ID= '"+txtID.Text+"'";
SqlCommand k = new SqlCommand(m, con);
k.ExecuteNonQuery();
con.Close();
MessageBox.Show("O'chirish amalga oshirildi !!!");
}
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'dekanatDataSet.talaba' table. You can move, or remove it, as needed.
this.talabaTableAdapter.Fill(this.dekanatDataSet.talaba);
}
}
}
Do'stlaringiz bilan baham: |