Bind or pull a DataTable entry into a MessageBox text in C #

I am trying to make message-body text provide datatable results. Below is a snippet of code that I have written so far:

String mystring = comboBox1.Text; if (mystring.Substring (0, 12) == ("Company Name")) {textBox2.Text = mystring.Substring (13); ADOCon.ConnectionString = @ "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = C: \ Users \ Name \ Desktop \ SmallBizDb.mdb"; ADOCon.Open ();

            OleDbCommandBuilder CBuilder = new OleDbCommandBuilder(DAdapter);
            DAdapter = new OleDbDataAdapter("Select Companies.Company_Name From Companies Where Companies.Company_Name = '" + textBox2.Text + "'", ADOCon);

            DAdapter.Fill(DTable);
            MessageBox.Show(DTable.ToString());
            ADOCon.Close();
            ADOCon.Dispose();
        }
        else

Basically, if the end user calls "Company Name-Company One," for example, I would like a message box with information about the datatable (DTable) that comes from the SQL query. I currently have "messagebox.Show (DTable.ToString ());" which does not work. In addition, all the other examples I've seen use Row indexes, such as ".Rows [0]", which I cannot use, because the row numbers are not involved, but rather the column names and record names from the sql operator "where" in adapter data.

There is a lot of fluff here, so my main problem is how to convert my data so that it appears in the message box.

Thanks,

Dfm

+3
source share
1

, , datatable, . , -

        System.Text.StringBuilder b = new System.Text.StringBuilder();
        foreach (System.Data.DataRow r in dt.Rows)
        {
            foreach (System.Data.DataColumn c in dt.Columns)
            {
                b.Append(c.ColumnName.ToString() + ":" + r[c.ColumnName].ToString());
            }
        }
        MessageBox.Show(b.ToString());

, ( ) ColumnName: ActualValue dataTable.

, , , , , .

+2

Source: https://habr.com/ru/post/1709059/


All Articles