see my code is working as I want to do, and I have taken idea from your suggestion to use "RowCount".
private void btn_Add_Click(object sender, EventArgs e)
{
int numberOfRows = dataGridView1.Rows.Count;
if (numberOfRows < 5)
{
MemoryStream ms = new MemoryStream();
pictureBox1.Image.Save(ms, pictureBox1.Image.RawFormat);
byte[] img = ms.ToArray();
dataGridView1.Rows.Add(txt_UserID.Text, txt_Name.Text, img);
}
else
{
MessageBox.Show("Please insert Only 5 Images");
}
}
private void btn_Save_Click(object sender, EventArgs e)
{
int numberOfRows = dataGridView1.Rows.Count;
if (numberOfRows == 5)
{
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
string col1 = dataGridView1.Rows[i].Cells[0].Value.ToString();
string col2 = dataGridView1.Rows[i].Cells[1].Value.ToString();
string col3 = dataGridView1.Rows[i].Cells[2].Value.ToString();
string insert_sql = "INSERT INTO Input(UserID, UserName, PassImage) VALUES ('" + col1 + "','" + col2 + "','" + col3 + "')";
this.getcom(insert_sql);
}
MessageBox.Show("Record Added");
}
else
{
MessageBox.Show("Please Enter 5 Images");
}
}