C# SQL Server生成系统参数异常

C# SQL Server生成系统参数异常,c#,sql-server,C#,Sql Server,我在C#中的SQL Server中遇到一个查询问题,队列的这一部分准备使用Microsoft report打印查询。我的问题是,当点击(checkedListBoxCosaStampare.SelectedIndex==1)时,我会得到下面列出的错误 我还有另一个问题,当选中复选框中的两个项目时,仅在第二个if时运行。我怎样才能修好它 错误: C#代码: 尝试将''作为Quantita更改为0作为Quantita尝试将''作为Quantita更改为0作为Quantita请共享“Mostra查询

我在C#中的SQL Server中遇到一个查询问题,队列的这一部分准备使用Microsoft report打印查询。我的问题是,当点击
(checkedListBoxCosaStampare.SelectedIndex==1)
时,我会得到下面列出的错误

我还有另一个问题,当选中复选框中的两个项目时,仅在第二个if时运行。我怎样才能修好它

错误:

C#代码:


尝试将
''作为Quantita更改为
0作为Quantita
尝试将
''作为Quantita更改为
0作为Quantita

请共享“Mostra查询”@Riccardo Pirani“输入字符串格式不正确”不是SQL Server错误消息。因此,这应该是您的C#错误消息。此代码非常容易受到SQL注入攻击。您应该使用参数化查询来保护数据不被窃取、损坏或删除。解释了风险,并提供了如何在C#@ADyson中安全编写查询的清晰示例。我知道,我只是在做一些测试时写得很糟糕。请共享“Mostra查询”@Riccardo Pirani“输入字符串格式不正确”不是SQL Server错误消息。因此,这应该是您的C#错误消息。此代码非常容易受到SQL注入攻击。您应该使用参数化查询来保护数据不被窃取、损坏或删除。解释了风险,并提供了如何在C#@ADyson中安全编写查询的清晰示例。我知道,我只是在做一些测试时写得太糟糕了。我能解决这个问题吗?如果是
CheckedListBox
而不是使用
checkedDices
则程序不会输入第一个复选框,而是显示选中的内容
SelectedIndex
显示当前光标位置如何解决问题?如果是
CheckedListBox
而不是使用
checkedDices
则程序不会输入第一个复选框,而是显示选中的内容
SelectedIndex
显示当前光标位置
// Stampa completa con prezzo
if (comboBoxStampe.Text== "Stampa con Prezzo")
{              
    try
    {
        //contro i valori cekkati:
        int contacheck = 0;
        //Devo effettuare tutti i controlli

        //Il ricarico non funziona correttamente con il punto quindi controllo se è presente il punto se c'è lo 
        //sostituisco con la ,
        if (textBoxRicarico.Text.Contains("."))
        {
            textBoxRicarico.Text = textBoxRicarico.Text.Replace(".", ",");
        }

        float Ricarico = float.Parse(textBoxRicarico.Text);

        //Setto la parte iniziale della query
        String Query = "SET LANGUAGE 'Italian' select Tipo, Data, GG, CodArt as 'CodArt',Descrizione,Quantita as 'Quantita',Prezzo,Totale from (  ";

        //Prima parte della query

        //controllo se gli articoli sono selezionati
        if (checkedListBoxCosaStampare.SelectedIndex == 0)
        {                        
            Query = Query + "Select 'A' as Tipo, CONVERT(VARCHAR(10), ArticoloCantiere.DataInserimento, 105) as Data, DATENAME(WEEKDAY, ArticoloCantiere.DataInserimento) as GG, ArticoloCantiere.CodArt, ArticoloCantiere.Descrizione, ArticoloCantiere.Quantita, (ArticoloCantiere.Prezzo+((ArticoloCantiere.Prezzo/100)*'"+Ricarico+"')) as Prezzo, (ArticoloCantiere.Prezzo+((ArticoloCantiere.Prezzo/100)*'"+Ricarico+"'))*Quantita as Totale  from Cantiere  inner join ArticoloCantiere  on Cantiere.IdCantiere = ArticoloCantiere.IdCantiere  where ArticoloCantiere.IdCantiere = '"+IdCantiere+"'  ";
            contacheck++;
        }

        //controllo le spese sostenute
        if (checkedListBoxCosaStampare.SelectedIndex == 1)
        {
            //controllo se è stato precendentemente selezionato qualcosa
            if (contacheck >0)
            {
                Query = Query + " union ";
            }

            Query = Query + " Select 'S' as Tipo, CONVERT(VARCHAR(10), SpeseSostenute.Data, 105) as Data, DATENAME(WEEKDAY, SpeseSostenute.Data) as GG, '' as CodArt, 'Causale: ' + SpeseSostenute.Causale + ' --- Descrizione: ' + DescrizioneLibera as Descrizione, '' as Quantita, (SpeseSostenute.Costo+((SpeseSostenute.Costo/100)*'"+Ricarico+"')) as Prezzo, '' as Totale  from SpeseSostenute  where IdCantiere = '"+IdCantiere+"'  ";
        }

        //setto la parte finale della query
        Query = Query + "    )Q order by Data ";

        MessageBox.Show("Mostra Query "+Query);

        //eseguo la stampa
        StampaCompletaCantiereconPrezzo s = new StampaCompletaCantiereconPrezzo();
        s.db = db;
        s.IdCantiere = IdCantiere;
        s.Query = Query;
        s.Show();

        this.Close();
    }
    catch(Exception ex)
    {
        MessageBox.Show("Controlla che tutti i campi siano compilati correttamente, errore: "+ex);
    }
}
else if(comboBoxStampe.Text== "Stampa senza Prezzo")
{
    MessageBox.Show("Stampa Disabilitata");
}
else if (comboBoxStampe.Text == "Stampa Rapportini")
{
    MessageBox.Show("Stampa Disabilitata");
}
else
{
    MessageBox.Show("Devi selezionare una stampa");
}