How I can read database table into a second gui holding a richtextbox.

Hector Agosto 21 Reputation points
2022-08-25T03:49:49.917+00:00
private: System::Void btnNotes_Click(System::Object^ sender, System::EventArgs^ e) {  
 MyForm1^ Form1 = gcnew MyForm1(txtRef->Text);  
 Form1->ShowDialog();  
}  

234707-screenshot-1.png
I have the reference number showing when the button loads on the second gui from a label, but I need the second gui to display the Notes table from my database in my richtextbox. any help?
234680-download.png

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,636 questions
{count} votes

Accepted answer
  1. Minxin Yu 11,026 Reputation points Microsoft Vendor
    2022-08-26T06:26:22.833+00:00

    Hi, @Hector Agosto

    This is the test example. Click button2 to read data and click button1 to show the Form1.

    private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {  
      
     form1 = gcnew MyForm1(myAL);  
    form1->ShowDialog();  
    }  
    private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {  
      
    String^ connString = "Data Source = (localdb)\\ProjectModels; Initial Catalog = DataBase1; Integrated Security = True; Connect Timeout = 30; Encrypt = False; TrustServerCertificate = False; ApplicationIntent = ReadWrite; MultiSubnetFailover = False";  
     SqlConnection^ con = gcnew SqlConnection(connString);  
     con->Open();  
     String^ sqly = "select * from TestTable";  
     SqlCommand^ sqlCommand = gcnew SqlCommand(sqly, con);  
     SqlDataReader^ reader = sqlCommand->ExecuteReader();  
     mTable->Load(reader);  
     reader->Close();  
     con->Close();  
      
    for each (DataRow^ row in mTable->Rows)  
    {  
    myAL->Add(row["Notes"]->ToString());  
    }  
      
      
      
    }  
    

    235109-image.png
    235079-image.png

    Best regards,

    Minxin Yu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


1 additional answer

Sort by: Most helpful
  1. Hector Agosto 21 Reputation points
    2022-08-25T08:58:30.677+00:00
    private: System::Void btnNotes_Click(System::Object^ sender, System::EventArgs^ e) {  
     MyForm1^ Form1 = gcnew MyForm1(txtRef->Text, myAL);  
     Form1->ShowDialog();  
      
     //MyForm1^form1 = gcnew MyForm1(myAL);  
     //form1->ShowDialog();  
      
      
    }  
    

    isnt working .