Server









How do I use Server
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: ClassDAL.cs Copy
12         public SqlConnection GetConnect()
13         {
14             return new SqlConnection("server=TY-PC;User id=sa;password=04091990;database=CNPM_1");
15         }
File name: FormBaoCao.cs Copy
40         private void btnLoc_Click(object sender, EventArgs e)
41         {
42             SqlConnection con = dal.GetConnect();
43             con.Open();
44             string sql = "select *from SinhVien where MaLop=@MaLop";
45             SqlDataAdapter da = new SqlDataAdapter(sql, con);
46             da.SelectCommand.Parameters.AddWithValue("@MaLop", cmbMaLop.SelectedValue.ToString());
47             DataTable dt = new DataTable();
48             da.Fill(dt);
49             crBaoCao cr = new crBaoCao();
50             ConnectionInfo crConnectionInfo = new ConnectionInfo();
51             crConnectionInfo.ServerName = "Ty-PC";
52             crConnectionInfo.DatabaseName = "CNPM_1";
53             crConnectionInfo.UserID = "sa";
54             crConnectionInfo.Password = "04091990";
55             TableLogOnInfos crTableLogonInfos = new TableLogOnInfos();
56             foreach (CrystalDecisions.CrystalReports.Engine.Table table in cr.Database.Tables)
57             {
58                 TableLogOnInfo crTableLogonInfo = new TableLogOnInfo();
59                 crTableLogonInfo.TableName = table.Name;
60                 crTableLogonInfo.ConnectionInfo = crConnectionInfo;
61                 crTableLogonInfos.Add(crTableLogonInfo);
62                 table.ApplyLogOnInfo(crTableLogonInfo);
63
64             }
65             crvHocKyHocPhan.LogOnInfo = crTableLogonInfos;
66             cr.SetDataSource(dt);
67             ParameterValues a = new ParameterValues();
68             ParameterDiscreteValue b = new ParameterDiscreteValue();
69             b.Value = cmbMaLop.SelectedValue.ToString();
70             a.Add(b);
71             cr.DataDefinition.ParameterFields["txtMaLop"].ApplyCurrentValues(a);
72             crvHocKyHocPhan.ReportSource = cr;
73             crvHocKyHocPhan.Show();
74         }
File name: frmCapNhat.cs Copy
19         public frmCapNhat()
20         {
21             sqlcon = new SqlConnection("server=.\\sqlexpress;database=QL_Thitracnghiem;integrated security =true");
22             sqlcon.Open();
23             InitializeComponent();
24         }
File name: frmDienTenTS.cs Copy
16         public frmDienTenTS()
17         {
18             string strCon = "server=.\\SQLEXPRESS;database=QL_Thitracnghiem;integrated security=true";
19             ObjCon = new SqlConnection(strCon);
20             ObjCon.Open();
21             InitializeComponent();
22
23         }
File name: frmKetQua.cs Copy
18         public frmKetQua(string strten, string strma, string strdiem, string strsocaudung)
19         {
20             string strCon = "server=.\\SQLEXPRESS;database=QL_Thitracnghiem;integrated security=true";
21             ObjCon = new SqlConnection(strCon);
22             ObjCon.Open();
23             InitializeComponent();
24
25
26             getvalueformdienten = strten;//ten
27             getvalueformdienma = strma;//ma thi sinh
28             getvaluediem = strdiem;//diem
29             getvaluesocaudung = strsocaudung;//so cau dung
30             socausai = 50 - int.Parse(strsocaudung);//so cau sai
31             lbsocausai.Text = socausai.ToString();
32         }
File name: frmLogin.cs Copy
66         private void btLog_Click(object sender, EventArgs e)
67         {
68             try
69             {
70                 if (txtdangnhap.Text == "" || txtmatkhau.Text == "")
71                 {
72                     MessageBox.Show("Bạn chưa điền đầy đủ thông tin", "Có lỗi xảy ra!");
73                     txtdangnhap.Focus();
74                     return;
75                 }
76                     if(txtdangnhap.Text=="admin" && txtmatkhau.Text=="admin")
77                     {
78                         if (MessageBox.Show("Chào mừng bạn đã đến với mục quản lý dành cho giáo viên", "Thông báo", MessageBoxButtons.OK) == DialogResult.OK)
79                         {
80                             this.Hide();
81                             frmQuanLy_Admin admin = new frmQuanLy_Admin();
82                             admin.ShowDialog();
83
84                         }
85
86                     }
87                 else
88                 {
89                     SqlConnection con = new SqlConnection("server=.\\SQLEXPRESS;database=QL_Thitracnghiem;integrated security=true");
90                     con.Open();
91                     SqlCommand cmd = new SqlCommand("Select MatKhau from THISINH where TenDangNhap ='" + txtdangnhap.Text + "'", con);
92                     SqlDataReader reader = cmd.ExecuteReader();
93                     reader.Read();
94                     if (txtmatkhau.Text == reader.GetValue(0).ToString())
95                     {
96                         MessageBox.Show("Bạn đã đăng nhập thành công!", "Thành công");
97                         reader.Close();
98                         con.Close();
99                         this.Close();
100                         frmLuaChon frmChon = new frmLuaChon();
101                         frmChon.ShowDialog();
102                         this.Hide();
103
104                     }
105                     else
106                     {
107                         MessageBox.Show("Sai Mật Khẩu");
108                         txtmatkhau.Focus();
109                     }
110                     reader.Close();
111                     con.Close();
112                 }
113
114             }
115
116             catch (Exception)
117             {
118
119                 MessageBox.Show("Tên đăng nhập và mật khẩu không hợp lệ","Có lỗi xảy ra");
120                 txtdangnhap.Focus();
121
122             }
123         }
File name: frmQuanLySinhVien.cs Copy
18         public frmQuanLySinhVien()
19         {
20             sqlcon = new SqlConnection("server=.\\SQLEXPRESS;database=QL_Thitracnghiem;integrated security =true");
21             sqlcon.Open();
22             InitializeComponent();
23         }
File name: frmReg.cs Copy
17         public frmReg()
18         {
19             string strCon ="server=.\\SQLEXPRESS;database=QL_Thitracnghiem;integrated security=true";
20             ObjCon = new SqlConnection(strCon);
21             ObjCon.Open();
22             InitializeComponent();
23         }
File name: frmThiThat.cs Copy
34         void Load_DeThiThat()
35         {
36             try
37             {
38                 SqlConnection cnn = new SqlConnection("server=.\\SQLEXPRESS;database=QL_Thitracnghiem;integrated security =true");
39                 SqlDataAdapter da = new SqlDataAdapter("select cauhoi.mach,cauhoi,a,b,c,d ,dapan from cauhoi,DAPAN where cauhoi.mach=DAPAN.mach", cnn);
40                 DataTable BangQuestion = new DataTable();
41                 da.Fill(BangQuestion);
42                 TaoBangRandomCauHoi(BangQuestion);
43             }
44             catch (Exception ex)
45             { MessageBox.Show(ex.Message); }
46             p = 60;//nhap thoi gian thi
47             s = 60;
48             h = 0;
49         }
File name: Lichsuthi.cs Copy
19         public frmLichsuthi()
20         {
21             sqlcon = new SqlConnection("server=.\\SQLEXPRESS;database=QL_Thitracnghiem;integrated security =true");
22             sqlcon.Open();
23             InitializeComponent();
24         }

Download file with original file name:Server

Server 149 lượt xem

Gõ tìm kiếm nhanh...