mysql - how to store null values in listbox c# -


I am developing a window store app and there are several list boxes to get the data in the database, it is my MySQL Database screenshot is

Enter image details here

that null After value the database list box is not filled with the data shown in the form of the following screenshot

 Enter image details here

I I want to keep blank values ​​blank and store other details How can I do this?

Here is the C # code

  Private Zero Button_View_Click (Object Sender, RoutedEventArgs E) {listb0.Items.Clear (); Listb1.Items.Clear (); Listb2.Items.Clear (); Listb3.Items.Clear (); Listb4.Items.Clear (); Try {string query = @ "SELECT * FROM` bcasdb` .`tbl_results`;"; // This is the command class which will handle the query and the connection object. MySqlConnection conn = New MySqlConnection (BCASApp.DataModel.DB_CON.connection); MySqlCommand CMD = New MySqlCommand (query, conn); MySqlDataReader MyReader; Conn.Open (); MyReader = cmd.ExecuteReader (); // This query will be executed and the data will be saved in the database. While (Myrador. Reid ()) {ListBoxItem itm0 = New ListBoxItem (); Itm0.Content = MyReader.GetString (0); This.listb0.Items.Add (itm0); ListBoxItem itm1 = New ListBoxItem (); Itm1.Content = MyReader.GetString (1); This.listb1.Items.Add (itm1); ListBoxItem itm2 = New ListBoxItem (); Itm2.Content = MyReader.GetString (2); This.listb2.Items.Add (itm2); ListBoxItem itm3 = New ListBoxItem (); Itm3.Content = MyReader.GetString (3); This.listb3.Items.Add (itm3); ListBoxItem itm4 = New ListBoxItem (); Itm4.Content = MyReader.GetString (4); This.listb4.Items.Add (itm4); } Conn.Close (); } Hold (exception) {errormsgBox (); }}  

If you want to work around this problem in code You need to check it Dibbullle using the databar method of deterord

  listboxItim itm2 = new ListBoxItem (); Itm2.Content = MyReader.IsDBNull (2)? "": MyReader.GetString (2); This.listb2.Items.Add (itm2);  

Of course this pattern should be applied to other columns which can potentially be nullified.


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

java - Messages from .properties file do not display UTF-8 characters -

javascript - amcharts makechart not working -