نمایش نتایج 1 تا 3 از 3

نام تاپیک: Input string was not in a correct format

  1. #1
    کاربر دائمی
    تاریخ عضویت
    شهریور 1382
    محل زندگی
    عالم ماده
    پست
    977

    Input string was not in a correct format

    SqlConnection myConnection;
    //----------------------------------------------------------------------------------------------------
    private void Page_Load(object sender, System.EventArgs e)
    {
    myConnection = new SqlConnection("server=(local);uid=sa;p wd=yaali;database=MDB");
    if (!IsPostBack) BindGrid();
    }
    //----------------------------------------------------------------------------------------------------
    public void BindGrid()
    {
    myConnection = new SqlConnection("server=(local);uid=sa;p wd=yaali;database=MDB");
    SqlDataAdapter myCommand = new SqlDataAdapter("SELECT * FROM" +
    " tblSupplies", myConnection);

    DataSet ds = new DataSet();
    myCommand.Fill(ds);

    MyDataGrid.DataSource=ds;
    MyDataGrid.DataBind();
    }
    //----------------------------------------------------------------------------------------------------
    private void AddAuthor_Click(object sender, System.EventArgs e)
    {
    if (name.Value == "" || Model.Value == "" ||
    DeviceType.Value == "" || EnterDate.Value == "")
    {
    Message.InnerHtml = "ERROR: Null values not allowed for" +
    " tblSupplies ID, Name or DeviceType";
    Message.Style["color"] = "red";
    BindGrid();
    return;
    }
    SqlConnection myConnection = new SqlConnection("server=(local);uid=sa;p wd=yaali;database=MDB");
    String insertCmd = "insert into tblSupplies values (name," +
    " ,model,DeviceType,GetType,EnterDate,FixRecord,Pric e,Force,Location,Answerable)";

    SqlCommand myCommand = new SqlCommand(insertCmd, myConnection);

    myCommand.Parameters.Add(new SqlParameter("@name",
    SqlDbType.NChar, 30));
    myCommand.Parameters["@name"].Value = name.Value;
    myCommand.Parameters.Add(new SqlParameter("@Model",
    SqlDbType.NChar, 10));
    myCommand.Parameters["@Model"].Value = Model.Value;
    myCommand.Parameters.Add(new SqlParameter("@DeviceType",
    SqlDbType.NChar, 10));
    myCommand.Parameters["@DeviceType"].Value = DeviceType.Value;
    myCommand.Parameters.Add(new SqlParameter("@GetType",
    SqlDbType.NChar, 10));
    myCommand.Parameters["@GetType"].Value = GetType1.Value;
    myCommand.Parameters.Add(new SqlParameter("@EnterDate",
    SqlDbType.NChar, 10));
    myCommand.Parameters["@EnterDate"].Value = EnterDate.Value;
    myCommand.Parameters.Add(new SqlParameter("@FixRecord",
    SqlDbType.NVarChar, 50));
    myCommand.Parameters["@FixRecord"].Value = FixRecord.Value;
    myCommand.Parameters.Add(new SqlParameter("@Price",
    SqlDbType.BigInt, 8));
    myCommand.Parameters["@Price"].Value = Price.Value;
    myCommand.Parameters.Add(new SqlParameter("@Force",
    SqlDbType.TinyInt,1));
    myCommand.Parameters["@Force"].Value = Force.Value;
    myCommand.Parameters.Add(new SqlParameter("@Location",
    SqlDbType.NChar,10));
    myCommand.Parameters["@Location"].Value = Location.Value;
    myCommand.Parameters.Add(new SqlParameter("@Answerable",
    SqlDbType.NChar,10));
    myCommand.Parameters["@Answerable"].Value =Answerable.Value;

    myCommand.Connection.Open();
    myCommand.ExecuteNonQuery();

    /*try
    {
    myCommand.ExecuteNonQuery();
    Message.InnerHtml = "<b>Record Added</b><br>" + insertCmd;
    }
    catch (SqlException e)
    {
    if (e.Number == 2627)
    Message.InnerHtml = "ERROR: A record already exists with" +
    " the same primary key";
    else
    Message.InnerHtml = "ERROR: Could not add record, please " +
    " ensure the fields are correctly filled out";
    Message.Style["color"] = "red";
    }*/

    myCommand.Connection.Close();

    BindGrid();
    }

    The name 'name' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted. 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Data.SqlClient.SqlException: The name 'name' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted.

    Source Error:


    Line 83:
    Line 84: myCommand.Connection.Open();
    Line 85: myCommand.ExecuteNonQuery();
    Line


  2. #2
    کاربر دائمی
    تاریخ عضویت
    شهریور 1382
    محل زندگی
    عالم ماده
    پست
    977
    داده های ورودی به ترتیب تکست باکس:
    q
    q
    q
    q
    34
    1000
    2
    w
    w

  3. #3
    کاربر دائمی
    تاریخ عضویت
    بهمن 1381
    محل زندگی
    ایران - تهران
    پست
    2,342
    برای مثال :

    myCommand.Parameters.Add(new SqlParameter("@Price", 
    SqlDbType.BigInt, 8));
    myCommand.Parameters["@Price"].Value = Price.Value;


    شما آنرا bigInt تعریف کرده اید اما ورودی آن تکست است باید Convert.ToInt32 کنید.

تاپیک های مشابه

  1. Format کردن یک فیلد String در DataGridview
    نوشته شده توسط ehsan_ansaripoor در بخش VB.NET
    پاسخ: 3
    آخرین پست: پنج شنبه 01 شهریور 1386, 01:31 صبح
  2. Datagarid ، Format String و تبدیل تاریخ به فارسی
    نوشته شده توسط MH2538 در بخش C#‎‎
    پاسخ: 5
    آخرین پست: چهارشنبه 12 اردیبهشت 1386, 19:54 عصر
  3. Format String Bug در Windows
    نوشته شده توسط saeedIRHA در بخش امنیت در نرم افزار و برنامه نویسی
    پاسخ: 4
    آخرین پست: سه شنبه 07 شهریور 1385, 19:41 عصر
  4. string.format
    نوشته شده توسط mehdi3683 در بخش VB.NET
    پاسخ: 2
    آخرین پست: یک شنبه 14 فروردین 1384, 01:56 صبح
  5. URL FORMAT STRING
    نوشته شده توسط faramarz_s در بخش ASP.NET Web Forms
    پاسخ: 1
    آخرین پست: پنج شنبه 17 مهر 1382, 18:19 عصر

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •