Click here to Skip to main content
15,606,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I have 2 datagridview, 1 richtextbox and 2 button

I want to do when I click the button1 create a table on datagridview1 and add the bulk datas from richtextbox to datagridview1 column

for example
No | Product Name
1    Apple
2    Banana
3    Pear
4    Orange....
..   ...

and when I click the button2 save as .xlsx file and list on datagridview2

What I can't make is adding bulk item to datagridview column from richtextbox all other I can do

what I'm asking how can I make this?

What I have tried:

using System.Data.OleDb;

        OleDbConnection odc = new OleDbConnection
            (@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Yusuf\Desktop\x\bilgiler.xlsx;Extended Properties='Excel 12.0 Xml; HDR=YES;IMEX=1;'");

        void veriler()
        {
            OleDbDataAdapter da = new OleDbDataAdapter("Select * From [bilgiler$]", odc);
            DataTable dt1 = new DataTable();
            da.Fill(dt1);
            dataGridView2.DataSource = dt1;
        }


private void button2_Click(object sender, EventArgs e)
{
    odc.Open();
    OleDbCommand cmd = new OleDbCommand("insert into [bilgiler$] (Products) values (@p1)",odc);
    cmd.Parameters.AddWithValue("@p1",richTextBox1.Text);
    cmd.ExecuteNonQuery();
    odc.Close();
    veriler();
}
Posted
Updated 18-May-22 2:05am
Comments
Richard MacCutchan 18-May-22 6:22am    
You will need to parse the text from the rich text box by separating the lines and fields into a corresponding set of DataGrid Rows and Columns.
YusufA0 18-May-22 6:30am    
let me try

1 solution

Since you have a DataTable as the DGV data source, the simplest solution is to put your new rows into another DataTable, and use the DataTable.Merge Method (System.Data) | Microsoft Docs[^]
 
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