-
Notifications
You must be signed in to change notification settings - Fork 0
/
Payment.cs
81 lines (67 loc) · 2.94 KB
/
Payment.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace Educational_Inistitute_Management
{
public partial class Payment : Form
{
public Payment()
{
InitializeComponent();
}
private void btnSave_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=MY-POTATO\SQLEXPRESS;Initial Catalog=edudb;Integrated Security=True;");
con.Open();
SqlCommand cnn = new SqlCommand("insert into paymenttab values(@paymentid,@studentid,@sectionid,@amountpaid)", con);
cnn.Parameters.AddWithValue("@PaymentId", int.Parse(textBox1.Text));
cnn.Parameters.AddWithValue("@StudentId", textBox2.Text);
cnn.Parameters.AddWithValue("@SectionId", textBox3.Text);
cnn.Parameters.AddWithValue("@AmountPaid", textBox4.Text);
cnn.ExecuteNonQuery();
con.Close();
MessageBox.Show("Paid successfully !", "Payment", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void btnNew_Click(object sender, EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
}
private void btnDisplay_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=MY-POTATO\SQLEXPRESS;Initial Catalog=edudb;Integrated Security=True;");
con.Open();
SqlCommand cnn = new SqlCommand("select * from sectionab", con);
SqlDataAdapter da = new SqlDataAdapter(cnn);
DataTable table = new DataTable();
da.Fill(table);
dataGridView1.DataSource = table;
}
private void button1_Click(object sender, EventArgs e)
{
using (SqlConnection con = new SqlConnection(@"Data Source=MY-POTATO\SQLEXPRESS;Initial Catalog=edudb;Integrated Security=True;"))
{
con.Open();
// Use a parameterized query to select only the specified StudentId
SqlCommand cnn = new SqlCommand("SELECT StudentId, AmountPaid FROM Paymenttab WHERE StudentId = @StudentId", con);
// Assuming txtStudentId is the TextBox where the user enters the Student ID
cnn.Parameters.AddWithValue("@StudentId", int.Parse(textBox2.Text));
SqlDataAdapter da = new SqlDataAdapter(cnn);
DataTable table = new DataTable();
da.Fill(table);
// Bind the result to the DataGridView to display
dataGridView1.DataSource = table;
}
}
}
}