public void LoadPermissionDetails() { DataTable dt_Det = new DataTable(); dt_Det.Clear(); SqlCommand cmd = new SqlCommand("Select * From PermissionDetails Where Per_id=@Per_id", conn); cmd.Parameters.AddWithValue("Per_id", NoTXT.Text); conn.Open(); dt_Det.Load(cmd.ExecuteReader()); conn.Close(); cmd = null; DataRow[] rows; rows = dt_Det.Select("Per_id = '" + NoTXT.Text + "'"); for (int i = 0; i < rows.Length; i++) { DataGridView1.CurrentRow.Cells["Colitem"].Value = rows[i][2].ToString(); } }
Select
select * from
using
dt_Det
DataTable dt = new DataTable(); using (SqlConnection conn = new SqlConnection("...")) using (SqlCommand cmd = new SqlCommand("SELECT YourColumnName FROM PermissionDetails WHERE Per_id = @Per_id", conn)) { cmd.Parameters.AddWithValue("@Per_id", NoTXT.Text); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Load(dt); } if (dt.Rows.Count != 0) { DataRow row = dt.Rows[dt.Rows.Count - 1]; DataGridView1.CurrentRow.Cells["Colitem"].Value = row[0]; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)