-3

I have form want to Auto Generate that ID from Primary Key so that code like that

private void setidphoto()
{
   DataTable dt = con.FillTable("SELECT IDPhoto FROM Produksi ORDER BY IDPhoto DESC");
      if (dt.Rows.Count == 0)
      {
         txtIdPhoto.Text = "PH001";
      }
      else {
         string temp = dt.Rows[0][0].ToString();
         int IDplus= int.Parse(temp.Substring(2)) + 1;
         string NewID = String.Format("PH{0:000}", IDPlus);
         txtIdPhoto.Text = NewID;
      }
}

The Error is con.FillTable cant compile or run it, can you help me

1 Answers1

0

Try this

SqlConnection con = new SqlConnection("yourconnectionstringhere");
SqlCommand com = new SqlCommand("SELECT IDPhoto FROM Produksi ORDER BY IDPhoto DESC", con);
SqlDataAdapter adp = new SqlDataAdapter(com);
DataTable dt = new DataTable();
add.SelectCommand = com;
adp.Fill(dt);
Mairaj Ahmad
  • 14,434
  • 2
  • 26
  • 40