本文介绍了在数据库中将字符串转换为int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
ASPX.CS代码
int[] no = new int[100];
int i = 0;
DataTable dt = bl.BL_AutogerateKey(txt_req_form_id.Text);
if (dt.Rows.Count == 0)
{
txt_req_form_id.Text = "1000001";
}
else
{
foreach (DataRow dr in dt.Rows)
{
no[i] = Convert.ToInt32(dr["FORM_ID"].ToString());
i++;
}
int auto = no.Max();
txt_req_form_id.Text = "100000" + Convert.ToString(auto + 1);
DataLayer
DataLayer
String str = "select substring(FORM_ID,5,50) as FORM_ID from PREV_REQUEST_TO_RECRUIT";
SqlDataAdapter da = new SqlDataAdapter(str, con);
DataSet ds = new DataSet();
da.Fill(ds);
DataTable dt = ds.Tables[0];
return dt;
我正在做自动生成form_id。但值100000在DB中存储为字符串,而我希望将其存储为int。我应该在C#代码中进行哪些更改以将其更改为整数?
I am doing auto generation of form_id. but the value "100000" is storing as string in DB whereas I want this to be stored as int. what alteration should I do in C# code to change it as integer?
推荐答案
txt_req_form_id.Text = "100000" + Convert.ToString(auto + 1);
with
with
txt_req_form_id.Text = Convert.ToString((100000 + auto + 1));
这篇关于在数据库中将字符串转换为int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!