How to Solve 2 digits after decimal from Excel to Datagridview?
up vote
0
down vote
favorite
I browse a score file excel to C# datagridview. The CGPA column is decimal column in excel file and it is formatted as Number and 2 digits after decimal, but when I browse it to Datagridview that column contains with more than 2 digits after decimal.
My Datagridview has not added any column, Means it will display the header columns with the select command.
this is my code in Browse Button:
private void btnbrowsefile_Click(object sender, EventArgs e)
{
OpenFileDialog openfill = new OpenFileDialog();
openfill.Filter = "Excel Files | *.xlsx;*.xls;*.xlsm";
if (openfill.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.txtchoose.Text = openfill.FileName;
}
OpenFileDialog openfile = new OpenFileDialog();
string stringconn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + txtchoose.Text + "; Extended Properties="Excel 12.0;HDR=Yes;";";
OleDbConnection con = new OleDbConnection(stringconn);
if (openfill.FileName == "")
{
MessageBox.Show("ເລືອກຂໍ້ມູນກ່ອນ ....", "ຂໍ້ມູນຫວ່າງເປົ່າ......", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
else
{
con.Open();
cmbSheet.DataSource = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
cmbSheet.DisplayMember = "TABLE_NAME";
cmbSheet.ValueMember = "TABLE_NAME";
}
}
The Sheet Members are displayed to the ComboBox named @cmbSheet.
After the Sheet selectcomitted, code as below:
string stringconn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + txtchoose.Text + "; Extended Properties="Excel 12.0;HDR=Yes;";";
OleDbConnection con = new OleDbConnection(stringconn);
OleDbDataAdapter sda = new OleDbDataAdapter("Select * from[" + cmbSheet.Text + "] ", con);
DataTable dt = new DataTable();
sda.Fill(dt);
dgvscore.DataSource = dt;
the Excel file has 2 Sheet Named(@January,@March) Score in 2 months, Each month has the same columns and it has 10 columns.
first Col is StudentID, Nexts are the Subjects Name and last two columns are Total Score and CGPA columns. The CGPA is formatted as 2 digits after decimal in Excel file but when I browse to Datagridview is more than 2 digits after decimal.
Any body can tell me how to solve this isue?
thank you.
c# excel
add a comment |
up vote
0
down vote
favorite
I browse a score file excel to C# datagridview. The CGPA column is decimal column in excel file and it is formatted as Number and 2 digits after decimal, but when I browse it to Datagridview that column contains with more than 2 digits after decimal.
My Datagridview has not added any column, Means it will display the header columns with the select command.
this is my code in Browse Button:
private void btnbrowsefile_Click(object sender, EventArgs e)
{
OpenFileDialog openfill = new OpenFileDialog();
openfill.Filter = "Excel Files | *.xlsx;*.xls;*.xlsm";
if (openfill.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.txtchoose.Text = openfill.FileName;
}
OpenFileDialog openfile = new OpenFileDialog();
string stringconn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + txtchoose.Text + "; Extended Properties="Excel 12.0;HDR=Yes;";";
OleDbConnection con = new OleDbConnection(stringconn);
if (openfill.FileName == "")
{
MessageBox.Show("ເລືອກຂໍ້ມູນກ່ອນ ....", "ຂໍ້ມູນຫວ່າງເປົ່າ......", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
else
{
con.Open();
cmbSheet.DataSource = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
cmbSheet.DisplayMember = "TABLE_NAME";
cmbSheet.ValueMember = "TABLE_NAME";
}
}
The Sheet Members are displayed to the ComboBox named @cmbSheet.
After the Sheet selectcomitted, code as below:
string stringconn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + txtchoose.Text + "; Extended Properties="Excel 12.0;HDR=Yes;";";
OleDbConnection con = new OleDbConnection(stringconn);
OleDbDataAdapter sda = new OleDbDataAdapter("Select * from[" + cmbSheet.Text + "] ", con);
DataTable dt = new DataTable();
sda.Fill(dt);
dgvscore.DataSource = dt;
the Excel file has 2 Sheet Named(@January,@March) Score in 2 months, Each month has the same columns and it has 10 columns.
first Col is StudentID, Nexts are the Subjects Name and last two columns are Total Score and CGPA columns. The CGPA is formatted as 2 digits after decimal in Excel file but when I browse to Datagridview is more than 2 digits after decimal.
Any body can tell me how to solve this isue?
thank you.
c# excel
The fact that Excel displays it as only 2 decimals doesn't mean it only has 2 decimals.
– mjwills
Nov 11 at 6:51
Possible duplicate of Formatting datagridview cell to 2 decimal places
– mjwills
Nov 11 at 6:51
@mjwills, it helps me.
– nco hlivaj
Nov 11 at 8:57
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I browse a score file excel to C# datagridview. The CGPA column is decimal column in excel file and it is formatted as Number and 2 digits after decimal, but when I browse it to Datagridview that column contains with more than 2 digits after decimal.
My Datagridview has not added any column, Means it will display the header columns with the select command.
this is my code in Browse Button:
private void btnbrowsefile_Click(object sender, EventArgs e)
{
OpenFileDialog openfill = new OpenFileDialog();
openfill.Filter = "Excel Files | *.xlsx;*.xls;*.xlsm";
if (openfill.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.txtchoose.Text = openfill.FileName;
}
OpenFileDialog openfile = new OpenFileDialog();
string stringconn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + txtchoose.Text + "; Extended Properties="Excel 12.0;HDR=Yes;";";
OleDbConnection con = new OleDbConnection(stringconn);
if (openfill.FileName == "")
{
MessageBox.Show("ເລືອກຂໍ້ມູນກ່ອນ ....", "ຂໍ້ມູນຫວ່າງເປົ່າ......", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
else
{
con.Open();
cmbSheet.DataSource = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
cmbSheet.DisplayMember = "TABLE_NAME";
cmbSheet.ValueMember = "TABLE_NAME";
}
}
The Sheet Members are displayed to the ComboBox named @cmbSheet.
After the Sheet selectcomitted, code as below:
string stringconn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + txtchoose.Text + "; Extended Properties="Excel 12.0;HDR=Yes;";";
OleDbConnection con = new OleDbConnection(stringconn);
OleDbDataAdapter sda = new OleDbDataAdapter("Select * from[" + cmbSheet.Text + "] ", con);
DataTable dt = new DataTable();
sda.Fill(dt);
dgvscore.DataSource = dt;
the Excel file has 2 Sheet Named(@January,@March) Score in 2 months, Each month has the same columns and it has 10 columns.
first Col is StudentID, Nexts are the Subjects Name and last two columns are Total Score and CGPA columns. The CGPA is formatted as 2 digits after decimal in Excel file but when I browse to Datagridview is more than 2 digits after decimal.
Any body can tell me how to solve this isue?
thank you.
c# excel
I browse a score file excel to C# datagridview. The CGPA column is decimal column in excel file and it is formatted as Number and 2 digits after decimal, but when I browse it to Datagridview that column contains with more than 2 digits after decimal.
My Datagridview has not added any column, Means it will display the header columns with the select command.
this is my code in Browse Button:
private void btnbrowsefile_Click(object sender, EventArgs e)
{
OpenFileDialog openfill = new OpenFileDialog();
openfill.Filter = "Excel Files | *.xlsx;*.xls;*.xlsm";
if (openfill.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.txtchoose.Text = openfill.FileName;
}
OpenFileDialog openfile = new OpenFileDialog();
string stringconn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + txtchoose.Text + "; Extended Properties="Excel 12.0;HDR=Yes;";";
OleDbConnection con = new OleDbConnection(stringconn);
if (openfill.FileName == "")
{
MessageBox.Show("ເລືອກຂໍ້ມູນກ່ອນ ....", "ຂໍ້ມູນຫວ່າງເປົ່າ......", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
else
{
con.Open();
cmbSheet.DataSource = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
cmbSheet.DisplayMember = "TABLE_NAME";
cmbSheet.ValueMember = "TABLE_NAME";
}
}
The Sheet Members are displayed to the ComboBox named @cmbSheet.
After the Sheet selectcomitted, code as below:
string stringconn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + txtchoose.Text + "; Extended Properties="Excel 12.0;HDR=Yes;";";
OleDbConnection con = new OleDbConnection(stringconn);
OleDbDataAdapter sda = new OleDbDataAdapter("Select * from[" + cmbSheet.Text + "] ", con);
DataTable dt = new DataTable();
sda.Fill(dt);
dgvscore.DataSource = dt;
the Excel file has 2 Sheet Named(@January,@March) Score in 2 months, Each month has the same columns and it has 10 columns.
first Col is StudentID, Nexts are the Subjects Name and last two columns are Total Score and CGPA columns. The CGPA is formatted as 2 digits after decimal in Excel file but when I browse to Datagridview is more than 2 digits after decimal.
Any body can tell me how to solve this isue?
thank you.
c# excel
c# excel
asked Nov 11 at 6:48
nco hlivaj
31
31
The fact that Excel displays it as only 2 decimals doesn't mean it only has 2 decimals.
– mjwills
Nov 11 at 6:51
Possible duplicate of Formatting datagridview cell to 2 decimal places
– mjwills
Nov 11 at 6:51
@mjwills, it helps me.
– nco hlivaj
Nov 11 at 8:57
add a comment |
The fact that Excel displays it as only 2 decimals doesn't mean it only has 2 decimals.
– mjwills
Nov 11 at 6:51
Possible duplicate of Formatting datagridview cell to 2 decimal places
– mjwills
Nov 11 at 6:51
@mjwills, it helps me.
– nco hlivaj
Nov 11 at 8:57
The fact that Excel displays it as only 2 decimals doesn't mean it only has 2 decimals.
– mjwills
Nov 11 at 6:51
The fact that Excel displays it as only 2 decimals doesn't mean it only has 2 decimals.
– mjwills
Nov 11 at 6:51
Possible duplicate of Formatting datagridview cell to 2 decimal places
– mjwills
Nov 11 at 6:51
Possible duplicate of Formatting datagridview cell to 2 decimal places
– mjwills
Nov 11 at 6:51
@mjwills, it helps me.
– nco hlivaj
Nov 11 at 8:57
@mjwills, it helps me.
– nco hlivaj
Nov 11 at 8:57
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53246482%2fhow-to-solve-2-digits-after-decimal-from-excel-to-datagridview%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The fact that Excel displays it as only 2 decimals doesn't mean it only has 2 decimals.
– mjwills
Nov 11 at 6:51
Possible duplicate of Formatting datagridview cell to 2 decimal places
– mjwills
Nov 11 at 6:51
@mjwills, it helps me.
– nco hlivaj
Nov 11 at 8:57