i have like 10 contacts on my database but the ID not Arrangement from 1 to 10 it like 1 2 3 5 6 8.... and im setting a button when click the lll1 is increase like lll1++ and Take lll1 value to ID so it display contacts by click button but when it get to number 4 or 7 for example (1 2 3 5 6 8....) the form stop and show error that Value Cannot be null is there way to skip number if not have value also when the ID of database finish like after 10 contacts when i press button and lll1 increase to 11 and database dont have contacts 11 it show same error Value cannot be null , help me plz this important to me thanks
private void button6_Click(object sender, EventArgs e)
{
OleDbConnection cn = new OleDbConnection();
cn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Database9.accdb";
OleDbCommand cmd = new OleDbCommand();
cn.Open();
cmd.Connection = cn;
cmd.CommandText = "Select * from Contacts where ID=" + lll1.Text;
OleDbDataReader reader = cmd.ExecuteReader();
string sql = "select Attachments.FileData from Contacts where ID =" + lll1.Text;
OleDbCommand vcom = new OleDbCommand(sql, cn);
byte[] ImageByte = (byte[])vcom.ExecuteScalar(); //contains 20 extra bytes
MemoryStream MemStream = new MemoryStream(ImageByte.Skip(20).ToArray()); //Read bytes starting at position 20
Image image = Image.FromStream(MemStream);
pictureBox1.Image = image;
while (reader.Read())
{
fl1.Text = reader.GetString(reader.GetOrdinal("First Name"));
}
cn.Close
}
public int o { get; set; }
private void button5_Click(object sender, EventArgs e)
{
o++;
lll1.Text = o.ToString();
button6_Click(sender, e);
}
` string sql = "select Attachments.FileData from Contacts where ID =" +
lll1.Text;
if (DBNull.Value.Equals("Attachments.FileData"))
{
MessageBox.Show("no value");
}
else
{
OleDbCommand vcom = new OleDbCommand(sql, cn);
byte[] ImageByte = (byte[])vcom.ExecuteScalar(); //contains 20
extra bytes
MemoryStream MemStream = new
MemoryStream(ImageByte.Skip(20).ToArray()); //Read byte starting at position 20
Image image = Image.FromStream(MemStream);
pictureBox1.Image = image;
}`