3
Answers

huge transfer with OleDbCommand

lemoinek

lemoinek

20y
2.4k
1
I have a strange problem. I have a .sql file that containts 3000 insert commands. I read every line and execute the command on the database. Till there there is no problem, it reads everything and executes everything. But if i watch to my datatransfer over the network, i have send and received 260Mb. That couldn't be normal. I work with OleDbCommand.ExecuteNonQuery, and maybe there will be the problem? this is my code: private OleDbConnection myConn; public create_database() { string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=//cpc-srv/datanl/testmap-stage/bank_database.mdb"; myConn = new OleDbConnection(connStr); myConn.Open(); } protected override void Dispose( bool disposing ) { myConn.Close(); } public string doe(string commando) { OleDbCommand comm = new OleDbCommand(commando,myConn); comm.ExecuteNonQuery(); } private void start(object sender, System.EventArgs e) { StreamReader objReader = new StreamReader("c:\\datab.sql"); string sLine=""; while (sLine != null) { sLine = objReader.ReadLine(); if (sLine != null && sLine!="") doe(sLine); } objReader.Close(); }
Answers (3)
0
Hemant Kumar

Hemant Kumar

NA 3k 215.1k 13y
If your column type is of number type(such as double), the formating would do the work no matter in edit mode or not.
If your column type is of string type which is by default, you shoud handle the cellFormating event to do a trick work like below:

Code Snippet

private void DgvCellStyle_Load(object sender, EventArgs e)

        {

            DataTable dt = new DataTable();

            dt.Columns.Add("a");

            dt.Rows.Add(155.6565);

            dt.Rows.Add(2342.2);

            this.dataGridView1.DataSource = dt;

 

            this.dataGridView1.CellFormatting += new DataGridViewCellFormattingEventHandler(dataGridView1_CellFormatting);

        }

 

        void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)

        {

            if (e.ColumnIndex == 0 && e.RowIndex != this.dataGridView1.NewRowIndex)

            {

                double d = double.Parse(e.Value.ToString());

                e.Value = d.ToString("N2");

            }

        }