Cách tạo chuỗi kết nối có thểm tham khảo tượng tự như bài https://blackblog.net/doc-du-lieu-tu-ms-sql-server-tu-c/
string constr = @"Server=DESKTOP-52N97T0\SQLEXPRESS;Database=todo;User Id=sa;Password=*****;";//thay ***** bang password that SqlConnection connection = new SqlConnection(constr); try { //Mo ket noi connection.Open(); //Chuan bi cau lenh query viet bang SQL String sqlQuery = "delete from users"; //Tao mot Sqlcommand de thuc hien cau lenh truy van da chuan bi voi ket noi hien tai SqlCommand command = new SqlCommand(sqlQuery, connection); //Thuc hien cau truy van command.ExecuteNonQuery(); } catch (Exception ex) { //xu ly khi ket noi co van de MessageBox.Show("Ket noi xay ra loi hoac doc du lieu bi loi"); } finally { //Dong ket noi sau khi thao tac ket thuc connection.Close(); }
More Stories
Game Battleship
GDI cơ bản
Cập nhật dữ liệu MS SQL từ C#