How i can read records from Database and Can insert into DataGridView
. I don't want to bind data source. Just want to read and insert using While Loop. I know how to read from Database Sql Server 2008 R2 Express Edition
But unable to insert records in Datagridview.
Can anyone help me please ?
string query = "Select id, IdNo, status From Members Where FamilyHeadIqama=@Head";
sqlCommand = new SqlCommand(query, sqlConnection);
sqlConnection.Open();
sqlCommand.Parameters.AddWithValue("@Head", familyMemberId);
sqlDataReader = sqlCommand.ExecuteReader();
if (sqlDataReader.HasRows)
{
//What to write here while my DataGridView Name is ufGView and it has
//4 column. Names are Id, IdNo{TextBox}, Status{CheckBox}, Action{HyperLink}
}
}
catch (Exception exp)
{
MessageBox.Show(exp.Message.ToString(), "Exception in CheckFamilyMembers");
}
I am looking for something like this.
int i = 0;
while (sqlDataReader.Read())
{
ufGview.Rows[i].Cells["Column3"].Value = sqlDataReader["id"].ToString();
ufGview.Rows[i].Cells["Column1"].Value = sqlDataReader["IdNo"].ToString();
ufGview.Rows[i].Cells["Column2"].Value = sqlDataReader["status"].ToString();
i++;
}