我有一个错误"输入字符串的格式不正确. [英] I have got an error " input string was not in a correct format."

查看:91
本文介绍了我有一个错误"输入字符串的格式不正确.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在提交销售时遇到了这个问题,数据已输入表中,但我们在页面上收到此错误消息,我们希望在屏幕上的捕获框中看到该消息.
请解决我的问题并将正确的代码发送给我.

我尝试过的事情:

I have got this issue when i was submit my sale, data have entered in table but we have got this error message on page , we want see message in catch box on our screen.
Kindly resolve my issue and send me correct code.

What I have tried:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class Index : System.Web.UI.Page
{
    JRDSQL jsql = new JRDSQL();
    JRDPopup jpop = new JRDPopup();
   // SqlConnection con = new SqlConnection(@"Data Source=103.209.144.175,1434; Initial Catalog=apbills_Anay;UId=apbills_Anay;Pwd=Lootbazzar@12345;");
  SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-LCOBDHV\SQLEXPRESS;Initial Catalog=anay_master;Integrated Security=true;");
       
    protected void Page_Load(object sender, EventArgs e)
    {
        bool blogin = false;
        if (Session["SID"] != null)
        {
            if (Convert.ToInt32(Session["SID"].ToString()) > 0)
            {
                blogin = true;
            }
        }
        if (blogin == true)
        {
            if (!IsPostBack)
            {

            }
        }
        else
        {
            Response.Redirect("Login.aspx", false);

        }

        //Checking Connection State and opening if closed
        if (con.State == ConnectionState.Closed)
        {
            con.Open();
        }
        if (!Page.IsPostBack)
        {

            //Call countries DropDownList on page load event
            BindCountry();
                fillDDSMN();
            
        }
    }
    protected void ddlcountry_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            int locationId = Convert.ToInt32(ddlcountry.SelectedValue);      
            //Select all States corresponding to the selected Country
            SqlDataAdapter adp = new SqlDataAdapter("select * from tbdealerlist where locationid= " +locationId + "Order by dealer_Name", con);
            DataSet ds = new DataSet();
            adp.Fill(ds);
            ddlstate.DataSource = ds;
            ddlstate.DataTextField = "Dealer_Name";
            ddlstate.DataValueField = "Dealer_Id";
            
            ddlstate.DataBind();
            ddlstate.Items.Insert(0, new ListItem("--Select--", "0"));
            
        }
        catch (Exception ex)
        {
            //Printing any exception if occcured.
            Response.Write("Error occured: " + ex.Message.ToString());
        }
        finally
        {
            //Close the connection
            con.Close();
        }      
    }

    
    //protected void ddlstate_SelectedIndexChanged(object sender, EventArgs e)
    //{
    //    try
    //    {
    //        int Dealer_Id = Convert.ToInt32(ddlstate.SelectedValue);
    //        //Select all Cities corresponding to the selected State
    //        SqlDataAdapter adp = new SqlDataAdapter("select * from tbdealerlist where Dealer_id=" + Dealer_id, con);
    //        DataSet ds = new DataSet();
    //        adp.Fill(ds);           
    //        ddlCity.DataSource = ds;
    //        ddlCity.DataTextField = "City_Name";
    //        ddlCity.DataValueField = "City_id_pk";
    //        ddlCity.DataBind();
    //        ddlCity.Items.Insert(0, new ListItem("--Select--", "0"));
    //    }
    //    catch (Exception ex)
    //    {
    //        Response.Write("Error occured : " + ex.Message.ToString());
    //    }
    //    finally
    //    {
    //        con.Close();
    //    }       
    //}

    protected void BindCountry()
    {

        try
        {

            SqlDataAdapter adp = new SqlDataAdapter("select * from Location order by location", con);
            DataSet ds = new DataSet();
            adp.Fill(ds);
            ddlcountry.DataSource = ds;
            ddlcountry.DataTextField = "Location";
            ddlcountry.DataValueField = "LocationId";
            
            ddlcountry.DataBind();
            ddlcountry.Items.Insert(0, new ListItem("--Select--", "0"));
            ddlstate.Items.Insert(0, new ListItem("--Select--", "0"));
            //ddlCity.Items.Insert(0, new ListItem("--Select--", "0"));
        }
        catch (Exception ex)
        {
            Response.Write("Error occured : " + ex.Message.ToString());
        }
        finally
        {
            con.Close();
        }
        
    }
    private void fillDDSMN()
    {
        SqlParameter[] paramdg = {new SqlParameter("@Mode","product")
            };
        jpop.PopupCombo(DDSMN, "sp_Registration", paramdg);
    }
    protected void submit_Click(object sender, EventArgs e)
    {
        try
        {

            SqlParameter[] paramsave = { new SqlParameter("@Mode","sale"),
                                     //  new SqlParameter("@saledate",txtsldate.Text.Trim()),
                                       new SqlParameter("@sale_Invoice",txtslinvoice.Text.Trim()),
                                       new SqlParameter("@Dealer_Name",ddlstate.SelectedValue),
                                       new SqlParameter("@SProduct_name",DDSMN.SelectedValue),
                                        new SqlParameter("@Model_name",DDSMN.SelectedValue),
                                       new SqlParameter("@SProduct_Qty",txtslmdlqty.Text.Trim()),
                                       new SqlParameter("@sale_rate",txtslrate.Text.Trim()),
                                       //new SqlParameter("@Scredit",nmbcrd.Text.Trim()),
                                        new SqlParameter("@Scash",nmbcsh.Text.Trim()),
                                       // new SqlParameter("@Scash",nmbcsh.Text.Trim()),
                                        //new SqlParameter("@Product_cat",ddSMC.SelectedValue), 
                                         new SqlParameter("daily_scash",nmbcsh.Text.Trim()),
                                         //new SqlParameter("Daily_Scredit",nmbcrd.Text.Trim()),
                                   };
     
           

            int id = 0;
            id = jsql.execStoredProcudure("sp_sale", paramsave);

            if (id > 0)
            {
                JRDMessage.UserMessage(this, "Data submitted successfully !!!");

            }
        }
        catch (Exception ex)
        {
            JRDMessage.UserMessage(this, ex.Message);
        }
    }




    }

推荐答案

输入字符串的格式不正确"不是我们可以为您解决的错误-意思是您在尝试什么转换不符合要转换的数据类型的规范.例如,如果要转换为整数,并且传递"Hello","1KG"或"17.8",则将得到错误.或者,如果您要转换为DateTime并传递错误的区域性日期-例如,当dd/MM/yy期望为MM/dd/yy时,则有时也会出现相同的错误.

首先完全不使用转换":如果您在会话中存储一个整数,请通过整数而不是通过ToString检索它.如果是用户输入,请使用TryParse或TryParseExact转换值(并向用户报告问题).

但是,由于这些是与数据相关的转换错误,因此我们无法帮助您解决它-我们无权访问您要转换的数据,只有您才能访问.
因此,使用调试器,找出要转换为的值.然后回溯以查找它如何变为无效值.

抱歉,但我们不能为您做到这一点!
"Input string was not in a correct format" is not an error we can fix for you - it''s saying that whatever you are trying to convert does not match the specification for the type of data you are converting to. For example, if you are converting to an integer and you pass "Hello", or "1KG", or "17.8" then you will get the error. Or if you are converting to a DateTime and you pass a date that is in the wrong culture - dd/MM/yy when it expects MM/dd/yy for example - you will also get the same error sometimes.

Start by not using Convert at all: If you store an integer in the Session, retrieve it as an integer, not via ToString. If it''s user input, use TryParse or TryParseExact to convert the values (and report problems to the user).

But because these are data-related conversion errors, we can;t help you fix it - we don''t have any access to the data you are trying to convert, only you do.
So use the debugger, and find out what value you are trying to convert to what. Then back track to find out how it became an invalid value.

Sorry, but we can''t do that for you!


这篇关于我有一个错误"输入字符串的格式不正确.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆