هر جا value یک سلول ممکنه null باشه قبلش چک کن و اگر null بود تصمیم بگیر و یا از convert.tostring استفاده کن.
هر جا از currentrow استفاده کردی قبلش چک کن null نباشه. (پیغام خطاها به خاطر عدم رعایت همین موضوعه)
به جای اندیس از نام ستون استفاده کن تا اگر ستونها جابجا شدن نیاز نباشه اندیس ها رو تغییر بدی.
یه فکری به حال سطوح دسترسی بکن. مثلا در حال حاضر هر شخصی وارد برنامه بشه میتونه نام و رمز عبور دیگران رو ببینه و حتی تغییر بده.(معمولا این طور فرض میشه که ممکنه از یک برنامه روی یک کامپیوتر چند نفر استفاده کنند.).
کوئری های sql رو با استفاده از پارامتر بنویس. قبلا مثال زده شده جستجو کنید.


private void dataGridView1_SelectionChanged(object sender, EventArgs e)
{
if (dataGridView1.CurrentRow != null)
{
txtName.Text = Convert.ToString(dataGridView1.CurrentRow.Cells["userName"].Value);
txtAge.Text = Convert.ToString(dataGridView1.CurrentRow.Cells["userAge"].Value);
txtSabeghe.Text = Convert.ToString(dataGridView1.CurrentRow.Cells["userSabeghe"].Value);
txtCodeMelli.Text = Convert.ToString(dataGridView1.CurrentRow.Cells["userCodeMelli"].Value);
txtTel.Text = Convert.ToString(dataGridView1.CurrentRow.Cells["userTel"].Value);
txtMobile.Text = Convert.ToString(dataGridView1.CurrentRow.Cells["userMobile"].Value);
txtAddress.Text = Convert.ToString(dataGridView1.CurrentRow.Cells["userAddress"].Value);
txtPass.Text = Convert.ToString(dataGridView1.CurrentRow.Cells["userPass"].Value);
}
}