私は英数字のIDを持っています。数値を自動インクリメント (+1) するにはどうすればよいですか?
調査IDはSVY0001~SVY9999に設定することになっています。
新しいアンケートを追加するたびに数字を 1 ずつ増やすにはどうすればよいですか?
現在、SVY が必須であるために、調査 ID テキスト ボックスに正規表現バリデーターがあります。
ValidationExpression="^SVY([0-9]{4})$"
教えてください。
これが私の .cs コードです。
protected void btnCreateSurvey_Click(object sender, EventArgs e)
{
SqlConnection connection = null;
SqlCommand command = null;
try
{
string connectionString = ConfigurationManager.ConnectionStrings["SurveyFdDBConnString"].ConnectionString;
connection = new SqlConnection(connectionString);
connection.Open();
string sql = "Insert into Survey (SurveyID, SurveyName, CreatedBy, DateCreated, Anonymous) Values " + "(@SurveyID, @SurveyName, @CreatedBy, @DateCreated, @Anonymous)";
command = new SqlCommand(sql, connection);
command.Parameters.AddWithValue("@SurveyID", txtBoxSurveyID.Text);
command.Parameters.AddWithValue("@SurveyName", txtBoxSurveyName.Text);
command.Parameters.AddWithValue("@CreatedBy", (string)Session["UserID"]);
command.Parameters.AddWithValue("@DateCreated", DateTime.Now);
command.Parameters.AddWithValue("@Anonymous", txtBoxAnonymous.Text);
int rowCount = command.ExecuteNonQuery();
if (rowCount != 0)
{
Session["SurveyID"] = txtBoxSurveyID.Text;
Response.Write("Survey created successfully.<br/>");
Response.Redirect("~/Admin/Select.aspx");
}
}
catch (Exception ex)
{
Response.Write("Error: " + ex.Message);
}
finally
{
connection.Close();
txtBoxSurveyID.Text = string.Empty;
txtBoxSurveyName.Text = string.Empty;
txtBoxAnonymous.Text = string.Empty;
}
}