Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hai there i have been trying to generate a list of databases to multi line textbox for futher use but i get system.data.row as list of error
every data base is lodedin my combobox1 as menu but....
error for multiline text


Imports System.Text
Imports MySql.Data.MySqlClient

Public Class Form1
  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

 Dim myCommand As New MySqlCommand
        Dim myAdapter As New MySqlDataAdapter
        Dim dataset As New DataSet
        Dim SQL As String
        Dim myData As New DataTable    
        Dim view As New DataView(myData)
        Dim connStr As String = "server=localhost;user=root;database=YourDATABasename;port=3306;password=YourPassWord;"
        Dim cmd As New MySqlCommand()
        Dim conn As New MySqlConnection(connStr)  
        Try
            conn.Open()
			 SQL = "Show Databases;"
        myCommand.Connection = conn
        myCommand.CommandText = SQL
        myAdapter.SelectCommand = myCommand
        myAdapter.Fill(myData)
        ComboBox1.DataSource = myData
        ComboBox1.DisplayMember = "Database"
            'MessageBox.Show("Connection Opened Successfully!")
        Catch myerror As MySqlException
            MessageBox.Show("Error was encountered when connecting" & myerror.Message)
        Finally

        End Try
        conn.Close()
    '---------------------------error Begning----------------------------------
	'this is where the errror is i get system.data.row like lise 	
        'For Each item In ComboBox1.Items
        '    MsgBox(item.ToString())
        '    Dim tem As String = (item.value).ToString & vbNewLine
        '    tempstring &= tempstring(item).ToString & vbNewLine
        '    MsgBox(tem)
        'Next
	'---------------------------------------------------------------------------	
TextBox1.Text = tempstring
    End Sub
End Class


What I have tried:

'---------------------------------------------------------------------------------------   
	   'For Each item In ComboBox1.Items
        '    MsgBox(item.ToString())
        '    Dim tem As String = (item.value).ToString & vbNewLine
        '    tempstring &= tempstring(item).ToString & vbNewLine
        '    MsgBox(tem)
        'Next
        'TextBox1.Text = 
        '    for each (DataRow row in myData.Rows)
        '            {
        '        For Each q In myData.Rows("Detail")
        'strDetail = Row of Column Detail
        '        Next
'---------------------------------------------------------------------------------------

        For Each item As DataColumn In myData.Columns
            ' MsgBox(CStr(row.ToString()))

            Dim rowValue As New ColumnValue
            rowValue.ColumnName = item.Caption
            'rowValue.ColumnValue = row.Item(item.Ordinal)
            'RowValues.Add(rowValue)
            'rowValue = Nothing
            'tempstring &= tempstring = CStr(row.ToString) & vbNewLine
            item.ToString()
            tempstring = tempstring & item.ToString & vbNewLine
        Next item

'---------------------------------------------------------------------------------------
        'Dim o As Object = myData.Rows.Item(1).Item("Column")
        'For i = 0 To 16

        '    Dim myStr As String = myData.Rows.Caption.ToString()
        '    tempstring = tempstring & myStr.ToString & vbNewLine
        'Next

'---------------------------------------------------------------------------------------

        'For Each myData In dataset.Tables
        '     For each row, print the values of each column.
        '        Dim row As DataRow
        '        For Each row In myData.Rows
        '            Dim column As DataColumn
        '            For Each column In myData.Columns
        '                Console.WriteLine(row(column))
        '                tempstring = tempstring & (row(column).caption) & vbNewLine
        '            Next column
        '        Next row
        '    Next myData
'---------------------------------------------------------------------------------------
        ' TextBox1.Text = tempstring
Posted
Updated 27-Dec-20 1:22am
Comments
Richard MacCutchan 26-Dec-20 3:41am    
What do you see in the message box at the following line:
MsgBox(item.ToString())
Member 10974007 26-Dec-20 5:04am    
i wanna a list of database from mysql to be in textbox1 as you can see in combobox1.txt
Member 10974007 26-Dec-20 5:05am    
combobox1
Member 10974007 26-Dec-20 5:10am    
system.data.row
Richard MacCutchan 26-Dec-20 5:41am    
Then you need to get the value from the row object.

1 solution

Here is the example code that might help you:

using System.Data.SqlClient;

namespace StackTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string connectionString = @"Data Source=(localdb)\Projects;Initial Catalog=DbTest;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False";
            string selectString = "select * from TblTest";
            textBox1.Multiline = true;

            SqlConnection conn = new SqlConnection(connectionString);
            SqlCommand cmd = new SqlCommand(selectString,conn);

            conn.Open();
            SqlDataReader rdr = cmd.ExecuteReader();

            while (rdr.Read())
            {
                textBox1.Text += rdr[0];
                textBox1.Text += rdr[1];
                //...
                textBox1.Text += Environment.NewLine;
            }

            conn.Close();                 
        }
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900