How to call specific cell in excel with c sharp?












0















enter image description here



I have an excel table with a horizontal column from 1 to 20 and a vertical column from 1 to 20. Furthermore, there is a word (string) in every cell. So, i will transfer the table to MySQL and connect it to c sharp. There will be two text boxes and a button. If i write a specific number in every text box, i will get the specific cell with the string. But for the first how do i call a specific cell ? And there a two parameters (two text boxes).



string query = "SELECT* FROM tb_patient_information ";
if (this.OpenConnection() == true)
{ //Create Command
MySqlCommand cmd = new MySqlCommand(query, connection);
//Create a data reader and Execute the command
MySqlDataReader dataReader = cmd.ExecuteReader();
while (dataReader.Read())
{ ... }









share|improve this question




















  • 1





    Very confusing. First off: a "horizontal column" is a "row". Then you do not query Excel but a MySql database table. dataReader holds one row with twenty fields (columns). Use dataReader[0].ToString() to get the fist value, or dataReader.getString(0) if you are certain that the field type of the first field is string. What do you mean with your "parameters" Unclear what exactly your problem is. Please try to formulate your question as precisely as possible and provide a Minimal, Complete, and Verifiable example.

    – LocEngineer
    Nov 14 '18 at 14:21











  • Sorry for confusing, my english is not so good. i add a pic of the table in my question (like a link). i have an row on the top an on the left side. the aim is to get a specific cell with one of the names in it. but the there a two rows. how can i do this ?

    – Binefş Aslan
    Nov 14 '18 at 14:38











  • You need to be clearer: are we talking about Excel or about a MySql table? Have you transferred the data to mySql including the numbers or just the grid with the strings in it? Finally: I assume you want to enter "4" and "3" into your text boxes and get back "john"?

    – LocEngineer
    Nov 14 '18 at 14:40











  • sorry for the circumstances.. we are talking about a mysql table! and yes i transferred it with the numbers and yes the main aim is to enter two number and get the specific cell

    – Binefş Aslan
    Nov 14 '18 at 14:43
















0















enter image description here



I have an excel table with a horizontal column from 1 to 20 and a vertical column from 1 to 20. Furthermore, there is a word (string) in every cell. So, i will transfer the table to MySQL and connect it to c sharp. There will be two text boxes and a button. If i write a specific number in every text box, i will get the specific cell with the string. But for the first how do i call a specific cell ? And there a two parameters (two text boxes).



string query = "SELECT* FROM tb_patient_information ";
if (this.OpenConnection() == true)
{ //Create Command
MySqlCommand cmd = new MySqlCommand(query, connection);
//Create a data reader and Execute the command
MySqlDataReader dataReader = cmd.ExecuteReader();
while (dataReader.Read())
{ ... }









share|improve this question




















  • 1





    Very confusing. First off: a "horizontal column" is a "row". Then you do not query Excel but a MySql database table. dataReader holds one row with twenty fields (columns). Use dataReader[0].ToString() to get the fist value, or dataReader.getString(0) if you are certain that the field type of the first field is string. What do you mean with your "parameters" Unclear what exactly your problem is. Please try to formulate your question as precisely as possible and provide a Minimal, Complete, and Verifiable example.

    – LocEngineer
    Nov 14 '18 at 14:21











  • Sorry for confusing, my english is not so good. i add a pic of the table in my question (like a link). i have an row on the top an on the left side. the aim is to get a specific cell with one of the names in it. but the there a two rows. how can i do this ?

    – Binefş Aslan
    Nov 14 '18 at 14:38











  • You need to be clearer: are we talking about Excel or about a MySql table? Have you transferred the data to mySql including the numbers or just the grid with the strings in it? Finally: I assume you want to enter "4" and "3" into your text boxes and get back "john"?

    – LocEngineer
    Nov 14 '18 at 14:40











  • sorry for the circumstances.. we are talking about a mysql table! and yes i transferred it with the numbers and yes the main aim is to enter two number and get the specific cell

    – Binefş Aslan
    Nov 14 '18 at 14:43














0












0








0








enter image description here



I have an excel table with a horizontal column from 1 to 20 and a vertical column from 1 to 20. Furthermore, there is a word (string) in every cell. So, i will transfer the table to MySQL and connect it to c sharp. There will be two text boxes and a button. If i write a specific number in every text box, i will get the specific cell with the string. But for the first how do i call a specific cell ? And there a two parameters (two text boxes).



string query = "SELECT* FROM tb_patient_information ";
if (this.OpenConnection() == true)
{ //Create Command
MySqlCommand cmd = new MySqlCommand(query, connection);
//Create a data reader and Execute the command
MySqlDataReader dataReader = cmd.ExecuteReader();
while (dataReader.Read())
{ ... }









share|improve this question
















enter image description here



I have an excel table with a horizontal column from 1 to 20 and a vertical column from 1 to 20. Furthermore, there is a word (string) in every cell. So, i will transfer the table to MySQL and connect it to c sharp. There will be two text boxes and a button. If i write a specific number in every text box, i will get the specific cell with the string. But for the first how do i call a specific cell ? And there a two parameters (two text boxes).



string query = "SELECT* FROM tb_patient_information ";
if (this.OpenConnection() == true)
{ //Create Command
MySqlCommand cmd = new MySqlCommand(query, connection);
//Create a data reader and Execute the command
MySqlDataReader dataReader = cmd.ExecuteReader();
while (dataReader.Read())
{ ... }






c# excel cell






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 17 '18 at 19:33









Hambone

10.2k52848




10.2k52848










asked Nov 14 '18 at 14:14









Binefş AslanBinefş Aslan

12




12








  • 1





    Very confusing. First off: a "horizontal column" is a "row". Then you do not query Excel but a MySql database table. dataReader holds one row with twenty fields (columns). Use dataReader[0].ToString() to get the fist value, or dataReader.getString(0) if you are certain that the field type of the first field is string. What do you mean with your "parameters" Unclear what exactly your problem is. Please try to formulate your question as precisely as possible and provide a Minimal, Complete, and Verifiable example.

    – LocEngineer
    Nov 14 '18 at 14:21











  • Sorry for confusing, my english is not so good. i add a pic of the table in my question (like a link). i have an row on the top an on the left side. the aim is to get a specific cell with one of the names in it. but the there a two rows. how can i do this ?

    – Binefş Aslan
    Nov 14 '18 at 14:38











  • You need to be clearer: are we talking about Excel or about a MySql table? Have you transferred the data to mySql including the numbers or just the grid with the strings in it? Finally: I assume you want to enter "4" and "3" into your text boxes and get back "john"?

    – LocEngineer
    Nov 14 '18 at 14:40











  • sorry for the circumstances.. we are talking about a mysql table! and yes i transferred it with the numbers and yes the main aim is to enter two number and get the specific cell

    – Binefş Aslan
    Nov 14 '18 at 14:43














  • 1





    Very confusing. First off: a "horizontal column" is a "row". Then you do not query Excel but a MySql database table. dataReader holds one row with twenty fields (columns). Use dataReader[0].ToString() to get the fist value, or dataReader.getString(0) if you are certain that the field type of the first field is string. What do you mean with your "parameters" Unclear what exactly your problem is. Please try to formulate your question as precisely as possible and provide a Minimal, Complete, and Verifiable example.

    – LocEngineer
    Nov 14 '18 at 14:21











  • Sorry for confusing, my english is not so good. i add a pic of the table in my question (like a link). i have an row on the top an on the left side. the aim is to get a specific cell with one of the names in it. but the there a two rows. how can i do this ?

    – Binefş Aslan
    Nov 14 '18 at 14:38











  • You need to be clearer: are we talking about Excel or about a MySql table? Have you transferred the data to mySql including the numbers or just the grid with the strings in it? Finally: I assume you want to enter "4" and "3" into your text boxes and get back "john"?

    – LocEngineer
    Nov 14 '18 at 14:40











  • sorry for the circumstances.. we are talking about a mysql table! and yes i transferred it with the numbers and yes the main aim is to enter two number and get the specific cell

    – Binefş Aslan
    Nov 14 '18 at 14:43








1




1





Very confusing. First off: a "horizontal column" is a "row". Then you do not query Excel but a MySql database table. dataReader holds one row with twenty fields (columns). Use dataReader[0].ToString() to get the fist value, or dataReader.getString(0) if you are certain that the field type of the first field is string. What do you mean with your "parameters" Unclear what exactly your problem is. Please try to formulate your question as precisely as possible and provide a Minimal, Complete, and Verifiable example.

– LocEngineer
Nov 14 '18 at 14:21





Very confusing. First off: a "horizontal column" is a "row". Then you do not query Excel but a MySql database table. dataReader holds one row with twenty fields (columns). Use dataReader[0].ToString() to get the fist value, or dataReader.getString(0) if you are certain that the field type of the first field is string. What do you mean with your "parameters" Unclear what exactly your problem is. Please try to formulate your question as precisely as possible and provide a Minimal, Complete, and Verifiable example.

– LocEngineer
Nov 14 '18 at 14:21













Sorry for confusing, my english is not so good. i add a pic of the table in my question (like a link). i have an row on the top an on the left side. the aim is to get a specific cell with one of the names in it. but the there a two rows. how can i do this ?

– Binefş Aslan
Nov 14 '18 at 14:38





Sorry for confusing, my english is not so good. i add a pic of the table in my question (like a link). i have an row on the top an on the left side. the aim is to get a specific cell with one of the names in it. but the there a two rows. how can i do this ?

– Binefş Aslan
Nov 14 '18 at 14:38













You need to be clearer: are we talking about Excel or about a MySql table? Have you transferred the data to mySql including the numbers or just the grid with the strings in it? Finally: I assume you want to enter "4" and "3" into your text boxes and get back "john"?

– LocEngineer
Nov 14 '18 at 14:40





You need to be clearer: are we talking about Excel or about a MySql table? Have you transferred the data to mySql including the numbers or just the grid with the strings in it? Finally: I assume you want to enter "4" and "3" into your text boxes and get back "john"?

– LocEngineer
Nov 14 '18 at 14:40













sorry for the circumstances.. we are talking about a mysql table! and yes i transferred it with the numbers and yes the main aim is to enter two number and get the specific cell

– Binefş Aslan
Nov 14 '18 at 14:43





sorry for the circumstances.. we are talking about a mysql table! and yes i transferred it with the numbers and yes the main aim is to enter two number and get the specific cell

– Binefş Aslan
Nov 14 '18 at 14:43












2 Answers
2






active

oldest

votes


















0














I'm not sure if this would be the direction you want to go but you can read the excel file directly with ClosedXML: https://github.com/closedxml/closedxml



string fileName = "C:\Folder\MyFile.xlsx";
var workbook = new XLWorkbook(fileName);
var ws1 = workbook.Worksheet(1);
var name = ws1.Cell("B3").Value;


You would also have the ability to edit and save.






share|improve this answer































    0














    OK. Your first row will be ignorable because it only contains numbers. Since the reader starts counting at 0 this is actually not bad. The first column values you can use as row index. The following should give you a good start:



    var rowNum = 0;
    var colNum = 0;

    var myResult = "";

    int.TryParse(textbox1.Text, out rowNum); //make sure the textbox contains a valid integer number
    int.TryParse(textbox2.Text, out colNum);

    if (rowNum > 0 && colNum > 0)
    {
    string query = "SELECT* FROM tb_patient_information WHERE rownum=@para1";
    using (var cmd = new MySqlCommand(query, connection))
    {
    cmd.Parameters.AddWithValue("@para1", rowNum);
    using (var dataReader = cmd.ExecuteReader())
    {
    dataReader.Read();
    myResult = dataReader.GetString(colNum);
    }
    }
    }





    share|improve this answer


























    • thank you it is good beginning but there is an error : "invalid attempt to access a field before calling Read."

      – Binefş Aslan
      Nov 14 '18 at 20:33











    • My bad. Needs a “dataReader.Read()” before the “myResult” line of course.

      – LocEngineer
      Nov 14 '18 at 20:36











    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',
    autoActivateHeartbeat: false,
    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%2f53302245%2fhow-to-call-specific-cell-in-excel-with-c-sharp%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I'm not sure if this would be the direction you want to go but you can read the excel file directly with ClosedXML: https://github.com/closedxml/closedxml



    string fileName = "C:\Folder\MyFile.xlsx";
    var workbook = new XLWorkbook(fileName);
    var ws1 = workbook.Worksheet(1);
    var name = ws1.Cell("B3").Value;


    You would also have the ability to edit and save.






    share|improve this answer




























      0














      I'm not sure if this would be the direction you want to go but you can read the excel file directly with ClosedXML: https://github.com/closedxml/closedxml



      string fileName = "C:\Folder\MyFile.xlsx";
      var workbook = new XLWorkbook(fileName);
      var ws1 = workbook.Worksheet(1);
      var name = ws1.Cell("B3").Value;


      You would also have the ability to edit and save.






      share|improve this answer


























        0












        0








        0







        I'm not sure if this would be the direction you want to go but you can read the excel file directly with ClosedXML: https://github.com/closedxml/closedxml



        string fileName = "C:\Folder\MyFile.xlsx";
        var workbook = new XLWorkbook(fileName);
        var ws1 = workbook.Worksheet(1);
        var name = ws1.Cell("B3").Value;


        You would also have the ability to edit and save.






        share|improve this answer













        I'm not sure if this would be the direction you want to go but you can read the excel file directly with ClosedXML: https://github.com/closedxml/closedxml



        string fileName = "C:\Folder\MyFile.xlsx";
        var workbook = new XLWorkbook(fileName);
        var ws1 = workbook.Worksheet(1);
        var name = ws1.Cell("B3").Value;


        You would also have the ability to edit and save.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 14 '18 at 16:17









        Clayton HarbichClayton Harbich

        272513




        272513

























            0














            OK. Your first row will be ignorable because it only contains numbers. Since the reader starts counting at 0 this is actually not bad. The first column values you can use as row index. The following should give you a good start:



            var rowNum = 0;
            var colNum = 0;

            var myResult = "";

            int.TryParse(textbox1.Text, out rowNum); //make sure the textbox contains a valid integer number
            int.TryParse(textbox2.Text, out colNum);

            if (rowNum > 0 && colNum > 0)
            {
            string query = "SELECT* FROM tb_patient_information WHERE rownum=@para1";
            using (var cmd = new MySqlCommand(query, connection))
            {
            cmd.Parameters.AddWithValue("@para1", rowNum);
            using (var dataReader = cmd.ExecuteReader())
            {
            dataReader.Read();
            myResult = dataReader.GetString(colNum);
            }
            }
            }





            share|improve this answer


























            • thank you it is good beginning but there is an error : "invalid attempt to access a field before calling Read."

              – Binefş Aslan
              Nov 14 '18 at 20:33











            • My bad. Needs a “dataReader.Read()” before the “myResult” line of course.

              – LocEngineer
              Nov 14 '18 at 20:36
















            0














            OK. Your first row will be ignorable because it only contains numbers. Since the reader starts counting at 0 this is actually not bad. The first column values you can use as row index. The following should give you a good start:



            var rowNum = 0;
            var colNum = 0;

            var myResult = "";

            int.TryParse(textbox1.Text, out rowNum); //make sure the textbox contains a valid integer number
            int.TryParse(textbox2.Text, out colNum);

            if (rowNum > 0 && colNum > 0)
            {
            string query = "SELECT* FROM tb_patient_information WHERE rownum=@para1";
            using (var cmd = new MySqlCommand(query, connection))
            {
            cmd.Parameters.AddWithValue("@para1", rowNum);
            using (var dataReader = cmd.ExecuteReader())
            {
            dataReader.Read();
            myResult = dataReader.GetString(colNum);
            }
            }
            }





            share|improve this answer


























            • thank you it is good beginning but there is an error : "invalid attempt to access a field before calling Read."

              – Binefş Aslan
              Nov 14 '18 at 20:33











            • My bad. Needs a “dataReader.Read()” before the “myResult” line of course.

              – LocEngineer
              Nov 14 '18 at 20:36














            0












            0








            0







            OK. Your first row will be ignorable because it only contains numbers. Since the reader starts counting at 0 this is actually not bad. The first column values you can use as row index. The following should give you a good start:



            var rowNum = 0;
            var colNum = 0;

            var myResult = "";

            int.TryParse(textbox1.Text, out rowNum); //make sure the textbox contains a valid integer number
            int.TryParse(textbox2.Text, out colNum);

            if (rowNum > 0 && colNum > 0)
            {
            string query = "SELECT* FROM tb_patient_information WHERE rownum=@para1";
            using (var cmd = new MySqlCommand(query, connection))
            {
            cmd.Parameters.AddWithValue("@para1", rowNum);
            using (var dataReader = cmd.ExecuteReader())
            {
            dataReader.Read();
            myResult = dataReader.GetString(colNum);
            }
            }
            }





            share|improve this answer















            OK. Your first row will be ignorable because it only contains numbers. Since the reader starts counting at 0 this is actually not bad. The first column values you can use as row index. The following should give you a good start:



            var rowNum = 0;
            var colNum = 0;

            var myResult = "";

            int.TryParse(textbox1.Text, out rowNum); //make sure the textbox contains a valid integer number
            int.TryParse(textbox2.Text, out colNum);

            if (rowNum > 0 && colNum > 0)
            {
            string query = "SELECT* FROM tb_patient_information WHERE rownum=@para1";
            using (var cmd = new MySqlCommand(query, connection))
            {
            cmd.Parameters.AddWithValue("@para1", rowNum);
            using (var dataReader = cmd.ExecuteReader())
            {
            dataReader.Read();
            myResult = dataReader.GetString(colNum);
            }
            }
            }






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 15 '18 at 8:37

























            answered Nov 14 '18 at 15:07









            LocEngineerLocEngineer

            2,24711022




            2,24711022













            • thank you it is good beginning but there is an error : "invalid attempt to access a field before calling Read."

              – Binefş Aslan
              Nov 14 '18 at 20:33











            • My bad. Needs a “dataReader.Read()” before the “myResult” line of course.

              – LocEngineer
              Nov 14 '18 at 20:36



















            • thank you it is good beginning but there is an error : "invalid attempt to access a field before calling Read."

              – Binefş Aslan
              Nov 14 '18 at 20:33











            • My bad. Needs a “dataReader.Read()” before the “myResult” line of course.

              – LocEngineer
              Nov 14 '18 at 20:36

















            thank you it is good beginning but there is an error : "invalid attempt to access a field before calling Read."

            – Binefş Aslan
            Nov 14 '18 at 20:33





            thank you it is good beginning but there is an error : "invalid attempt to access a field before calling Read."

            – Binefş Aslan
            Nov 14 '18 at 20:33













            My bad. Needs a “dataReader.Read()” before the “myResult” line of course.

            – LocEngineer
            Nov 14 '18 at 20:36





            My bad. Needs a “dataReader.Read()” before the “myResult” line of course.

            – LocEngineer
            Nov 14 '18 at 20:36


















            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53302245%2fhow-to-call-specific-cell-in-excel-with-c-sharp%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

            Xamarin.iOS Cant Deploy on Iphone

            Glorious Revolution

            Dulmage-Mendelsohn matrix decomposition in Python