簡體   English   中英

輸入的字符串格式不正確(ASP.NET)

[英]Input string was not in a correct format (ASP.NET)

string s1 = DropDownList1.SelectedItem.Text;
        string s2 = DropDownList2.SelectedItem.Text;
        string sql1 = ("Select Case_Type_Value FROM Case_Type where Case_Type_Text IS'" + s1 + "' ");
        string sql2 = ("Select Case_Status_Value FROM Case_Status where Case_Status_Text IS'" + s2 + "' ");
        int v1 = Int32.Parse(sql1);
        int v2 = Int32.Parse(sql2);

嗨,我收到以下錯誤信息:輸入字符串的格式不正確:int v1 = Int32.Parse(sql1);

當然,您會得到一個錯誤! 看到您不是從數據庫中獲取結果。 相反,您將查詢分配給sql1並嘗試將其轉換為整數。 請參見下面的代碼,您實際上是將整個選擇查詢分配給字符串sql1。您可以嘗試以下操作:

        string sql1 = ("Select Case_Type_Value FROM Case_Type where Case_Type_Text IS'" + s1 + "' ");
        string sql2 = ("Select Case_Status_Value FROM Case_Status where Case_Status_Text IS'" + s2 + "' ");
sqlconnection con = new SqlConnection("Blah Blah")
    Sqlcommand cmd = new sqlcommand(sql1,con);
con.open();
     int v1 = Convert.toint32(cmd.ExecuteScalar());
con.close();
con.Dispose();

您收到的是哪種類型

string sql1 = ("Select Case_Type_Value FROM Case_Type where Case_Type_Text IS'" + s1 + "' ");
    string sql2 = ("Select Case_Status_Value FROM Case_Status where Case_Status_Text IS'" + s2 + "' ");

您可以做一件事,就像在Usertype中輸入“ Group”列一樣。 獲取一個會話變量並捕獲其中的用戶名,然后獲取該用戶名所屬的組。 根據角色將用戶重定向到其相應頁面。

    Session["unmae"]=txtuname.text;
string username=Session["unmae"].Text;
string group=obj.getgroup(username);
if(group=="Admin")
{
Response.Redirect("1.aspx");
}
else if(group=="User")

{
Response.Redirect("2.aspx");
}
else
{
Response.Redirect("error.aspx");
}

希望這可以幫助。 快樂編碼

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM