Autor Beitrag
Talemantros
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 444
Erhaltene Danke: 2

Win7 Proff 64bit
C# (VS2013)
BeitragVerfasst: Mi 16.12.15 12:59 
Hallo zusammen,
ich habe ein UserControl, welches per BindingSource Daten laden soll über folgende Methode

ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
        public static Article GetArticleDetailsEdit(long ware)
        {
            Article myArticle = new Article();
            strSQl = "Select * from bestand where bestandid=?bestandid";

            using (MySqlConnection conn = new MySqlConnection(connStr))
            {
                using (MySqlCommand cmd = new MySqlCommand(strSQl, conn))
                {
                    conn.Open();

                    cmd.Parameters.AddWithValue("?bestandid", ware);

                    MySqlDataReader dr = cmd.ExecuteReader();

                    while (dr.Read())
                    {

                        myArticle.Id = dr.GetInt64("bestandid");
                        myArticle.Customer = dr.GetInt64("kundeid");
                        myArticle.CustomerTp = dr.GetInt64("kundetpid");
                        myArticle.CustomerUnit = dr.GetInt64("kundeunitid");
                        myArticle.CustomerCrap = dr.GetInt64("schrottartid");
                        myArticle.Container = dr.GetInt64("behaelterid");
                        myArticle.ContainerNumber = Convert.ToString(dr["behaelternummer"]);
                        myArticle.CrapBrutto = Convert.ToDecimal(dr["bgewicht"]);
                        myArticle.CrapNetto = Convert.ToDecimal(dr["ngewicht"]);
                        myArticle.StockPlace = Convert.ToInt64(dr["lagerplatzid"]);
                        myArticle.CrapColor = dr.GetString("farbe");
                        //myArticle.ContainerWithout = Convert.ToInt64(dr["behaelterohneid"]);
                        myArticle.ContainerWithout = dr.GetInt64("behaelterohneid");
                    }

                    conn.Close();
                }
            }
            
            return myArticle;
        }


Jetzt kann es sein, dass in der Datenbank einige der INt64 Felder NULL sein kann.
Und da bekomme ich dann das Problem, dass er das nicht laden kann. Siehe Anlage für den Fehler!

Kann mir hier jemand sagen, wie ich das verändern kann?

Danke

Gruß
Daniel
Einloggen, um Attachments anzusehen!
Ralf Jansen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 4700
Erhaltene Danke: 991


VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
BeitragVerfasst: Mi 16.12.15 13:34 
Du mußt halt testen ob da DBNull drinsteht.

ausblenden C#-Quelltext
1:
2:
if(dr["schrottartid"] != DBNull.Value)
    myArticle.CustomerCrap = dr.GetInt64("schrottartid");
Talemantros Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 444
Erhaltene Danke: 2

Win7 Proff 64bit
C# (VS2013)
BeitragVerfasst: Mi 16.12.15 13:53 
Super,
vielen Dank.

Sorry, für die doofe Frage :-(
Hatte irgendwie das Gefühl, dass in die Methoden zum Lesen und Schreiben eine IF Falsch wäre und nicht weiter drüber nachgedacht.
Einfach zu kompliziert gedacht.
Danke

Schönen Tag noch

Gruß
Daniel