What's wrong in my code

Socarsky

Well-known member
Joined
Mar 3, 2014
Messages
59
Programming Experience
Beginner
What's wrong in my code that cause a crach when I click on the combobox arrow


private void ConnPervasive()
        {
            Form1.populate();
            getDBname = Form1.passDBname;

            // Pervasive Sql connection string
            string ConnStrPSql = "Server Name=XXXXX;Database Name=" + getDBname + ";User ID=administrator;Password=XXXXXXX;";
        
            using (PsqlConnection conn = new PsqlConnection(ConnStrPSql)) 
            {
                try 
                {
                    conn.Open();

                    string strPSqlCmd1 = "SELECT A.R_KAYNAKKODU as Tezgah, B.AD as TezgahAdi FROM xxx A LEFT OUTER JOIN xxxx B ON A.R_KAYNAKKODU = B.KOD WHERE A.EVRAKNO = '" + AddWhiteSpace(txtMPS.Text) + "' AND A.ACIK_KAPALI = '' AND B.AD <> ''";
                
                    using (PsqlCommand command = new PsqlCommand(strPSqlCmd1, conn))
                    {
                        DataTable dt = new DataTable();
                        dt.Columns.Add(new DataColumn("Tezgah", typeof(string)));
                        dt.Columns.Add(new DataColumn("TezgahAdi", typeof(string)));

                        PsqlDataReader reader = command.ExecuteReader(CommandBehavior.Default);
                        DataRow myRow;
                        while (reader.Read()) 
                        {
                            myRow = dt.NewRow();
                            myRow.ItemArray[0] = reader[0];
                            myRow.ItemArray[1] = reader[1];
                            dt.Rows.Add(myRow);
                        }
                        reader.Close();
                        comboBox1.DisplayMember = "Tezgah";
                        comboBox1.DrawMode = DrawMode.OwnerDrawVariable;
                        comboBox1.ColumnWidths = "50;150";
                        comboBox1.DataSource = dt;
                        comboBox1.Text = String.Empty;
                
                        if (dt != null && dt.Rows.Count > 0) 
                        {
        
                            MessageBox.Show("Harika bir kac kayit var");
                        } 
                        else 
                        {
                            MessageBox.Show("==> There is not any record in Database! \n ~~> Tidak ada itu MPS nomor dalam Database!");
                        }
                    }
                } 
                catch 
                {
                    MessageBox.Show("Database Connection Problem Occurred!.");
                }
            }
        }
 
A crash is an unhanded exception. If an exception goes unhandled while debugging then the IDE displays the Exception Assistant window, which provides an error message and a stack trace, which includes the location at which the exception was thrown. Have you even looked at that information? It is provided to help you diagnose the issue. If you want us to diagnose the issue then would it not make sense to provide us with that information?

If the exception is not being thrown while debugging then that begs the question, why is it unhandled? In that case, the first thing to do is add exception handling and then you can get the same information. Ideally, all applications should include a global exception handler anyway, so that you can catch unexpected exceptions, log them and then exit gracefully instead of crashing.
 
Hi jmcilhinney, first if all sorry about not expressing exception condition. Unfortunately there is not any exception thrown. That's why I cannot follow a sign of the matter to fix.
There is one thing that makes me suspicions using of ItemArray. I'll try to use its example which shows in MSDN.
 
I very much doubt that there's no exception but, regardless, have you debugged the code? You should already know exactly what line of code you get to at least. Put a breakpoint at the top of the code and then step through it line by line. You can quickly determine which is the last line executed so then you can put a breakpoint on that line and then examine closely the state of the app on that line next time through.
 
I know debugging generally but this this crash as you can guess that occurs in runtime when I click arrow of the MultiColunmComboBox. I try to do my best with debugging. Thanks
 
I caught something I think. But It will be difficult to fix this.. This is comes from MultiColumnComboBox's class with I converted from VB.Net. :(
ubound.jpg

Hmm I got something related UBound, I have to figure out where it uses in .Net, because converter made a method to describe it.
 
Hi jmcilhinney,
How can I write UBound method with below details? This is blocked my way to get ahead.
ubound_issue.png
 
Hi jmcilhinney,
How can I write UBound method with below details? This is blocked my way to get ahead.

Noone should be using UBound in VB even. Did you check what UBound does in VB? It's not hard to find out, although it should be fairly obvious just from the usage. How would you usually do that same thing in C#?
 
Noone should be using UBound in VB even. Did you check what UBound does in VB? It's not hard to find out, although it should be fairly obvious just from the usage.

Below article gives ideas of LBound and UBound well..
ubound1a.jpg

How would you usually do that same thing in C#?
I never done that yet in C#.
 
Finally I solve the matter with inquiring things. Yay It's nicely to handle a matter even it can be a simple :)
Here is my solution: Bu now I must focus ItemArray.. because my combobox is empty.
ubound_sorun_cozuldu.png
 
I never done that yet in C#.

Surely you've used a `for` loop over an array in C# before, or at least seen one.
for (int i = 0; i < myArray.Length; i++)
 
Back
Top Bottom