Sign up ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

Hi I am trying to insert a float value into database through SqlDatasource.InsertParameter but after SqlDatasource.Insert() function is executed I only see the Integer part of it inserted in database. I have also debugged and checked that before the execution of SqlDatasource.Insert() the value stored in SqlDatasource is float. Below are my code:

Function from data layer:

     public static SqlDataSource DataSourceInsert(string sp, string[,] param)
{
    float f;
    ds = new SqlDataSource();
    if (cns.State != ConnectionState.Open)
        cns.Open();
    ds.ConnectionString = ConfigurationManager.ConnectionStrings["cns"].ConnectionString;
    ds.InsertCommandType = SqlDataSourceCommandType.StoredProcedure;
    ds.InsertCommand = sp;

    for (int i = 0; i < param.GetLength(1); i++)
    {
        ds.InsertParameters.Add(param[0, i], param[1, i]);
        ds.InsertParameters[param[0, i]].DefaultValue = param[1, i];
        if(float.TryParse(param[1, i],out f))
            ds.InsertParameters[param[0, i]].Type = System.TypeCode.Double;
    }
    ds.Insert();
    return ds;
}

Parameter P

protected void DV_ItemInsert(object sender, DetailsViewInsertEventArgs e)
{
    string procname = "spAddandInsertProduct";
    string[,] p = new string[2, 5];
    p[0, 0] = "ProductName";
    p[1, 0] = ((TextBox)((DetailsView)sender).Rows[0].Cells[1].Controls[0]).Text;
    p[0, 1] = "Description";
    p[1, 1] = ((TextBox)((DetailsView)sender).Rows[1].Cells[1].Controls[0]).Text;
    p[0, 2] = "IsPublished";
    p[1, 2] = ((TextBox)((DetailsView)sender).Rows[2].Cells[1].Controls[0]).Text;
    p[0, 3] = "Quantity";
    p[1, 3] = ((TextBox)((DetailsView)sender).Rows[3].Cells[1].Controls[0]).Text;
    p[0, 4] = "Price";
    p[1, 4] = ((TextBox)((DetailsView)sender).Rows[4].Cells[1].Controls[0]).Text;
    ds = SQLInteractor.DataSourceInsert(procname, p);

    ProdAdmin_insertDV.DataSource = ds;
    ProdAdmin_insertDV.DataBind();
    GV_databind();
}
share|improve this question
    
What is the definition of param? –  DavidG Jul 10 at 19:37
    
Thats not readable. Its a string array. –  Shubham Kumar Jul 10 at 19:39
1  
That doesn't tell me what param is. Also, please edit the details into your question. –  DavidG Jul 10 at 19:40
    
Done. Added both the complete functions –  Shubham Kumar Jul 10 at 20:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.