Question How to transfer selectnode to gridview

ucanmoruk

Member
Joined
Apr 8, 2019
Messages
5
Programming Experience
Beginner
I'm building a bot that goes to the links and take the title to the database by gridview. But when I push the button, just the last link's title coming all the column on database. How do I do this separately for each line?

I ay using Visual Studio, Windows Forms and Devexpress

The sum of button code:
for (int i = 0; i < gridView1.RowCount; i++)
{
string kaynak = gridView1.GetRowCellValue(i, colKaynak_Link).ToString();
urlal(kaynak, "//*[@id='cph1_lblKabulTar']", gridView1);
}

And the void urlal codes ::
public void urlal(string Url, string xpath, DevExpress.XtraGrid.Views.Grid.GridView Control)

url = new Uri(Url);
WebClient client = new WebClient();
client.Encoding = Encoding.UTF8;
html = client.DownloadString(url);
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(html);
for (int i = 0; i < gridView1.RowCount; i++)
{
int id = Convert.ToInt32(gridView1.GetRowCellValue(i, colDoküman_id));
baglanti.Open();
SqlCommand guncelle = new SqlCommand("Update dokuman set Kontrol_Tarihi=@s2 WHERE Doküman_id = @dokumanId", baglanti);
 guncelle.Parameters.AddWithValue("s2", doc.DocumentNode.SelectSingleNode(xpath).InnerText);
guncelle.Parameters.AddWithValue("dokumanId", id);
guncelle.ExecuteNonQuery();
baglanti.Close();
}
 
Why do you have a for loop inside your urlal method? You have this in the calling code:
C#:
for (int i = 0; i < gridView1.RowCount; i++)
and then that same line again inside the method you're calling. That doesn't make sense.
 
I just want to run urlal method for each line on gridview database. But i didn't. When i remove the for loop, the result is the same again.
 
I just want to run urlal method for each line on gridview database.
Then what was the loop inside that method supposed to be achieving?
When i remove the for loop, the result is the same again.
If your code has changed then show us the new code. Before that, however, have to actually debugged the code for yourself? You should be doing that before posting here so, if you haven't, do so now. I'm not talking about simply running the code and looking at the app as a user. I'm talking about being a developer, i.e. setting breakpoints, stepping through the code line by line and examining the state of all your variables, etc, at each step to ensure that the code does exactly what you expect and, if it doesn't, observing exactly what it does wrong. If you have debugged, where EXACTLY in the code does the state first differ from your expectations and what EXACTLY is the data in use at the time?
 
I am a beginner on c#. I am trying to do something by researching.

Here I just want a bot to go the each link on database and take the title of the link to the opposite line of it on database.

When i do that on a listbox it is works.

C#:
        public void urlal(string Url, string xpath, ListBox Sonuc)
        {
            try
            {
                url = new Uri(Url);
            }
            catch (UriFormatException)
            {
                if (MessageBox.Show("hatalı url-1!", "Hata", MessageBoxButtons.OK) == DialogResult.OK)
                {

                }
            }
            catch (ArgumentNullException)
            {
                if (MessageBox.Show("hatalı url-2!", "Hata", MessageBoxButtons.OK) == DialogResult.OK)
                {

                }
            }

            WebClient client = new WebClient();
            client.Encoding = Encoding.UTF8;
            try
            {
                html = client.DownloadString(url);
            }
            catch (WebException)
            {
                if (MessageBox.Show("hatalı url-3!", "Hata", MessageBoxButtons.OK) == DialogResult.OK)
                {

                }
            }

            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            doc.LoadHtml(html);

            try
            {
               Sonuc.Items.Add(doc.DocumentNode.SelectSingleNode(xpath).InnerText);
            }
            catch (NullReferenceException)
            {
                if (MessageBox.Show("hatalı xpath!", "Hata", MessageBoxButtons.OK) == DialogResult.OK)
                {

                }
            }

 
        }

But when i turn it to gridview and database, it take the last url to the each line.
 
Back
Top Bottom