1
Answer

update multiple rows data in MySQL using c#

siva nathan

siva nathan

4y
1.5k
1
Hi all,
Can anyone pls tell me how to update multiple rows data in MySql using c#
 
 
 
Answers (1)
4
Naimish Makwana

Naimish Makwana

136 13.8k 200.3k 1y

It seems like you’re using Selenium with C#, and you’re trying to use Select and getText(). In C#, the equivalent methods are a bit different:

  1. Select: In C#, to select an option from a dropdown, you would typically use the SelectElement class from the OpenQA.Selenium.Support.UI namespace1. Here’s an example:
IWebElement dropdown = driver.FindElement(By.Id("id")); // replace "id" with the id of your dropdown
SelectElement selectElement = new SelectElement(dropdown);
selectElement.SelectByText("Option"); // replace "Option" with the option you want to select
  1. getText(): In C#, the equivalent of getText() is Text property1. Here’s an example:
IWebElement element = driver.FindElement(By.Id("id")); // replace "id" with the id of your element
string text = element.Text;

If you’re still facing issues, you might need to check if you have the necessary Selenium WebDriver bindings for .NET installed. You can do this by going to the NuGet package manager in Visual Studio and checking if Selenium.WebDriver and Selenium.Support packages are installed2.

If they’re not installed, you can install them by running the following commands in the Package Manager Console:

Install-Package Selenium.WebDriver
Install-Package Selenium.Support

Please replace "id" and "Option" with the actual id of your dropdown and the actual option you want to select respectively. If you have any specific requirements.

Thanks

4
Naimish Makwana

Naimish Makwana

136 13.8k 200.3k 1y

To pull all the dropdown elements into separate rows of a DataGridView, you can follow these steps:

  1. First, get all the elements from the dropdown. Here’s how you can do it in Selenium:
Select dropdown = new Select(driver.FindElement(By.Id("id"))); // replace "id" with the id of your dropdown
List<WebElement> dd = dropdown.getOptions();
  1. Then, for each element in the dropdown, create a new row in the DataGridView and set the value of the cell in that row to the text of the dropdown element. Here’s a basic example:
foreach (WebElement option in dd)
{
    int rowIndex = dataGridView1.Rows.Add(); // Add a new row
    dataGridView1.Rows[rowIndex].Cells["YourColumnName"].Value = option.getText(); // replace "YourColumnName" with the name of your column
}

This will create a new row for each dropdown element and set the value of a cell in that row to the text of the dropdown element12.

Please replace "id" and "YourColumnName" with the actual id of your dropdown and the actual name of your column respectively. Also, please make sure that the DataGridView allows adding new rows. You can set dataGridView1.AllowUserToAddRows = true; to allow this.

Remember, this is a basic example. Depending on your exact requirements and the structure of your DataGridView, you might need to adjust this code. For example, if you have multiple columns and you want to add values to them, you would need to set the values for those cells too. If you have any specific requirements.

Thanks

3
Mehmet Fatih

Mehmet Fatih

817 947 48.3k 1y

I have changed my codes as in the following. But I still have a problem. I want to list a lesson in each line. All courses are listed in a single line. How can I correct this situation.?The second problem is how can I print these in the 3rd column?

IList<IWebElement> selectElements = drv.FindElements(By.Id("dersler"));
foreach (IWebElement select in selectElements)
{
    var selectElement = new SelectElement(select);
    List<string> lst = new List<string>();
    lst.Add(select.Text);
    DataTable dt = new DataTable();
    DataColumn dtcol = new DataColumn(select.Text);
    dt.Columns.Add(dtcol);
    for (int i = 0; i < lst.Count; i++)
    {
       dataGridView1.DataSource = dt;
    }

}

3
Naimish Makwana

Naimish Makwana

136 13.8k 200.3k 1y

Can you paste you error in english ?

3
Mehmet Fatih

Mehmet Fatih

817 947 48.3k 1y

Both Package Selenium.WebDriver and Package Selenium.Support are intalled. I hve tried the second alternative but nothing seems. I modifed the first alternative like that 

      IList<IWebElement> options = drv.FindElements(By.Id("dersler")); // tüm dropdown listesini veriri 

    for (int i = 0; i < options.Count; i++)
    {

        IWebElement element = drv.FindElement(By.Id("ddlDersler")); // replace "id" with the id of your element
                                                                    //string text = element.Text;
        int rowIndex = dataGridView1.Rows.Add(); // Add a new row
        dataGridView1.Rows[rowIndex].Cells[1].Value = element.Text.ToString();


    }
}

But in this case I am getting the following error.

3
Mehmet Fatih

Mehmet Fatih

817 947 48.3k 1y

I am getting errors in these circled places. Do I need to upload anything to nuGet?

2
Mehmet Fatih

Mehmet Fatih

817 947 48.3k 1y

Naimish, the error code English is like that "Rows cannot be programmatically added to the datagridview's rows collection when the control is data bound."