Cách truy vấn dữ liệu c#
Truy vấn 1 giá trị ta dùng hàm ExecuteScalar trong c# 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 kncsdlhocba { public partial class Truyvandulieudondong : Form { public Truyvandulieudondong() { InitializeComponent(); } SqlConnection conec = null; string ketnoi = @”Server =DESKTOP-CR8PM8TSQLEXPRESS; Database=CSDLSANPHAM ; User ID=sa; pwd =123″; private void btnXem_Click(object sender, EventArgs e) { if (conec==null) { conec = new SqlConnection(ketnoi); } if (conec.State == ConnectionState.Closed) { conec.Open(); } SqlCommand command = new SqlCommand(); command.CommandType = CommandType.Text; […]