C#exception == 0 SQL [英] C# exception ==0 SQL

查看:71
本文介绍了C#exception == 0 SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将以下异常应用于我的脚本..



I would like to apply the following exception to my script..

ListBoxKlanten.Items.Count == 0





想法是当列表框ListBoxKlanten.Items.Count == 0将listBoxKlantenContact设为空白。 (有可能在listBoxKlantenContact中有准备好的记录)如何应用此异常以及我可以为此选项最好地使用哪些代码







The idea is that when the listbox "ListBoxKlanten.Items.Count == 0" that the "listBoxKlantenContact" is made blank. (it is possible that there ready records in "listBoxKlantenContact") How do I apply this exception and what code can I best use for this option


private void KlantenContactBOX()
{

    string queryKLantID = "SELECT IDKlantContactpersonen, FK_ID_Klant, Naam From Klantencontact WHERE FK_ID_Klant = @SELKlantID";

    using (connection = new SqlConnection(connectionstring))
    using (SqlCommand command = new SqlCommand(queryKLantID, connection))
    using (SqlDataAdapter adapter = new SqlDataAdapter(command))

    {
        command.Parameters.AddWithValue("@SELKlantID", ListBoxKlanten.SelectedValue);

        DataTable KlantenContactlijst = new DataTable();
        adapter.Fill(KlantenContactlijst);

            listBoxKlantenContact.DisplayMember = "Naam";
            listBoxKlantenContact.ValueMember = "IDKlantContactpersonen";
            listBoxKlantenContact.DataSource = KlantenContactlijst;
   }
}

推荐答案

问题解决了,谢谢你的帮助!!



Problem solved, Thank you for your help!!

if (ListBoxKlanten.Items.Count == 0)
               {
                   command.Parameters.AddWithValue("@SELKlantcontactinfoID", DBNull.Value);
               }
               else
               {
                   command.Parameters.AddWithValue("@SELKlantcontactinfoID", listBoxKlantenContact.SelectedValue);
               }


这篇关于C#exception == 0 SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆