4
Answers

Unable to update converted datatype column

Ask a question
Vignesh Kumar

Vignesh Kumar

10y
1.4k
1
Hi,
I am using the below code to update my grid rows. Since my dollar column is of int datatype and I want to show them as western number system, I had done some conversions to display the dollar values like this " $ 100,00". Also when I update I am using the below code to trim the dollar and empty space for dollar column.

string Dollar = Dollars.Text.ToString();
string RemoveDollar = Dollar.Substring(2, Dollar.Length - 2);

Code:

protected void Details_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
TextBox Code = (TextBox)ODetails.Rows[e.RowIndex].FindControl("txtCode");
TextBox Date = (TextBox)Details.Rows[e.RowIndex].FindControl("txtDate");
TextBox Dollars = (TextBox)Details.Rows[e.RowIndex].FindControl("txtDollars");
TextBox Funding = (TextBox)Details.Rows[e.RowIndex].FindControl("txtFunding");
sring Dollar = Dollars.Text.ToString();
string RemoveDollar = Dollar.Substring(2, Dollar.Length - 2);
SqlConnection conn = new SqlConnection(CS);
Details.EditIndex = -1;
conn.Open();
SqlCommand cmd = new SqlCommand("Update Application set Date= '" + Date.Text + "', Funding= '" + Funding.Text + "' where Code= '" + Code.Text + "' and '$ ' + replace(convert(varchar(100), convert(money, Dollar_Amount), 1), '.00', '')= '" + Dollars.Text + "'", conn); cmd.ExecuteNonQuery(); conn.Close();
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alert", "alert('Details updated successfully');", true);
BindGrid();
}

Except Dollar column I am able to update remaining fields.



Answers (4)