Code Snippet
- Código: Seleccionar todos
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
if (e.CommandName == "comprar")
{
DropDownList ddlqt = ((DropDownList)e.Item.FindControl("DropDownList1"));
Label lblvalor =((Label)e.Item.FindControl("ValorLabel"));
Label lblprod = ((Label)e.Item.FindControl("ID_ProdLabel"));
Int32 qt = Int32.Parse(ddlqt.SelectedValue);
Double valor = Double.Parse(lblvalor.Text);
Int32 prod = Int32.Parse(lblprod.Text);
//string a = ddlqt.SelectedValue;
Double total = qt * valor;
SqlConnection ligacao;
SqlCommand comando;
ligacao = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["BDLojaConnectionString"].ConnectionString);
string inserir = "INSERT INTO [Vendas] ([Quantidade], [Produto], [Mes], [Data], [Total], [Utilizador]) VALUES (" + qt + ", " + prod + ", " + DateTime.Now.Month.ToString() + ", " + DateTime.Now + ", " + total + ", " + Membership.GetUser(Page.User.Identity.Name).ProviderUserKey.ToString() +")";
ligacao.Open();
comando = new SqlCommand(inserir, ligacao);
comando.ExecuteNonQuery();
ligacao.Close();
}
}
O campo que eu quero preencher esta definico como uniqueidentifier, penso que esteja correcto.
Estoura quando chega a parte de enviar o provideduserkey para a BD. diz que " Warning: the floating point value '...' is too small. It will be interpreted as 0."


