【问题标题】:Can help me to make Auto Generate ID?可以帮我制作自动生成ID吗?
【发布时间】:2016-01-07 10:35:26
【问题描述】:

我有表单想要从主键自动生成该 ID 这样的代码

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;
      }
}

错误是con.FillTable无法编译或运行,你能帮帮我吗

【问题讨论】:

  • 同时添加 FillTable 方法的代码。
  • @Bayeni:先生,怎么样?你能帮我写信吗?
  • con.FillTable 是什么?
  • @MairajAhmad : 不能像那个先生那样填写表格吗?

标签: c# sql-server visual-studio primary-key


【解决方案1】:

试试这个

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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-06
    • 2020-10-25
    • 2017-01-07
    • 1970-01-01
    • 1970-01-01
    • 2016-11-05
    相关资源
    最近更新 更多