-2
public partial class addtheatre : System.Web.UI.Page
{
    bal objbal = new bal();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
             DataSet ds = objbal.getid();
            int s;
            string d = "9T000";
            string c = ds.Tables[0].Rows[0][0].ToString();
            if (c == "")
            {
                s = 1;
                d = "9T000" + s;
            }
            else
            {

              s = Convert.ToInt32(c);
                s = s + 1;
                if (s < 999)
                {
                    d = "9T000" + s;
                }
                //s = Convert.ToInt32(c);
                else if (s == 1000)
                {
                    d = "T1000";
                }
                else if (s > 1000)
                {
                    d = "T1000" + s;
                }

            }
            TextBox1.Text = d.ToString();
        }
    }
}

转换时显示为错误(输入字符串的格式不正确)。
在数据库中,我采取dvarchar.

4

3 回答 3

2

我猜错误来自这里:

s = Convert.ToInt32(c);

如果 的值c不是整数的字符串表示形式(例如"123"),您会在此处遇到异常。您可以在调试器中(例如在 Visual Studio 中)检查 的值c以查看问题所在。

于 2012-12-23T14:19:22.550 回答
1

我猜错误来自这里:

试试下面的代码

int.TryParse(c,out s );

希望这会帮助你。

于 2012-12-23T15:11:09.937 回答
0

除了 Mark Byers 给出的 and 之外,
您可能应该使用
int.TryParse(string)orint.Parse(string)将字符串转换为 int。

于 2012-12-23T14:28:34.513 回答