-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAddCourse.cs
50 lines (48 loc) · 1.45 KB
/
AddCourse.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
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.SqlClient;
namespace WindowsFormsApp1
{
public partial class AddCourse : Form
{
public AddCourse()
{
InitializeComponent();
}
private void AddCour_Click(object sender, EventArgs e)
{
string sql = "insert into Course(Course_Id ,Course_Name ,Course_Specialty) values(@id,@name,@CS)";
string sql1 = "select count(*) from Course where Course_Name = @Name";
SqlParameter[] pm =
{
new SqlParameter("@id",int.Parse(tbCourseId.Text)),
new SqlParameter("@name",tbCourseName.Text.Trim()),
new SqlParameter("@CS",tbCourSpec.Text.Trim())
};
SqlParameter[] pm1 =
{
new SqlParameter("Name",tbCourseName.Text.Trim())
};
int i = (int)SqlHelper.ExecuteScalar(sql1,pm1);
if (i > 0)
{
MessageBox.Show(tbCourseName.Text + "已存在!");
}
else
{
int r = SqlHelper.ExecuteNonQuery(sql, pm);
if (r > 0)
{
MessageBox.Show("成功添加!");
}
}
}
}
}