首页上一页 1 下一页尾页 1 条记录 1/1页
有关substring 的问题
发表在ASP.NET图书答疑
2010-04-07
是否精华
是
否
版块置顶:
是
否
DAL: //保存选项
public int SavaChoiceid(ResultInfo resultinfo)
{
int savaid = 0;
SqlConnection conn = voteconnManger.ReconnectionStrings();
try
{
conn.Open();
using (SqlCommand cmd = new SqlCommand("insert into T_Result values('" + resultinfo.choiceid + "')", conn))
{
savaid = (int)cmd.ExecuteNonQuery();
}
}
catch (SqlException se)
{
throw se;
}
finally
{
if (conn.State != System.Data.ConnectionState.Closed)
{
conn.Close();
conn.Dispose();
}
}
return savaid;
}
BLL: //保存选项
public int SavaChoiceid(ResultInfo resultinfo)
{
return new VoteDAL.ResultDAL().SavaChoiceid(resultinfo);
}
//保存数据
protected void btnSavachoiceItem_Click(object sender, EventArgs e)
{
string voteresult = "";
string strTemp = "";
for (int i = 0; i < this.gvchoiceitem.Rows.Count ; i++)
{
strTemp = getselbygrid(gvchoiceitem.Rows[i].FindControl("rdosub") as RadioButtonList);
if (strTemp == "")
{
Response.Write("<script>alert('每个投票项目必须选择一票,请重试!')</script>");
break;
}
voteresult = voteresult + strTemp + ",";
}
voteresult = voteresult.Substring(0,voteresult.Length-1);
//string[] splits = new string[voteresult.Length];
//for (int i = 0; i < voteresult.Length; i++)
//{
// splits[i] = voteresult.Substring(i, 1);
//}
ResultInfo result = new ResultInfo();
result.choiceid = Convert.ToInt32(voteresult);
int j = new VoteBLL.ResultBLL().SavaChoiceid(result);
if (j > 0)
{
Response.Write("<script>alert('您的投票已经成功保存,感谢您的参与!')</script>");
}
else
{
Response.Write("<script>alert('您的投票失败,请核实!')</script>");
}
result.choiceid = Convert.ToInt32(voteresult);
这句有问题 voteresult是一个string集,里面有“1,4,7”这样的数据 如何转换成int 型上传到数据库里呢?
public int SavaChoiceid(ResultInfo resultinfo)
{
int savaid = 0;
SqlConnection conn = voteconnManger.ReconnectionStrings();
try
{
conn.Open();
using (SqlCommand cmd = new SqlCommand("insert into T_Result values('" + resultinfo.choiceid + "')", conn))
{
savaid = (int)cmd.ExecuteNonQuery();
}
}
catch (SqlException se)
{
throw se;
}
finally
{
if (conn.State != System.Data.ConnectionState.Closed)
{
conn.Close();
conn.Dispose();
}
}
return savaid;
}
BLL: //保存选项
public int SavaChoiceid(ResultInfo resultinfo)
{
return new VoteDAL.ResultDAL().SavaChoiceid(resultinfo);
}
//保存数据
protected void btnSavachoiceItem_Click(object sender, EventArgs e)
{
string voteresult = "";
string strTemp = "";
for (int i = 0; i < this.gvchoiceitem.Rows.Count ; i++)
{
strTemp = getselbygrid(gvchoiceitem.Rows[i].FindControl("rdosub") as RadioButtonList);
if (strTemp == "")
{
Response.Write("<script>alert('每个投票项目必须选择一票,请重试!')</script>");
break;
}
voteresult = voteresult + strTemp + ",";
}
voteresult = voteresult.Substring(0,voteresult.Length-1);
//string[] splits = new string[voteresult.Length];
//for (int i = 0; i < voteresult.Length; i++)
//{
// splits[i] = voteresult.Substring(i, 1);
//}
ResultInfo result = new ResultInfo();
result.choiceid = Convert.ToInt32(voteresult);
int j = new VoteBLL.ResultBLL().SavaChoiceid(result);
if (j > 0)
{
Response.Write("<script>alert('您的投票已经成功保存,感谢您的参与!')</script>");
}
else
{
Response.Write("<script>alert('您的投票失败,请核实!')</script>");
}
result.choiceid = Convert.ToInt32(voteresult);
这句有问题 voteresult是一个string集,里面有“1,4,7”这样的数据 如何转换成int 型上传到数据库里呢?