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.










share|improve this question






















  • 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

















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.










share|improve this question






















  • 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















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.










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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




















  • 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



















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Full-time equivalent

さくらももこ

13 indicted, 8 arrested in Calif. drug cartel investigation