Answer the question
In order to leave comments, you need to log in
DataGrid and parsing?
There is a code for parsing a link in the grid and deleting a row from the grid (I still can’t do it from the database). But, there is a problem, when I press parsing, a window pops up (which I made (Message) about the request to delete a row, and parsing does not occur. Tell me, how can I fix it?
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)<br/>
{<br/>
/*---Удаление строки---*/<br/>
<br/>
if (e.RowIndex != -1)<br/>
{<br/>
DialogResult result = MessageBox.Show("Вы УВЕРЕНЫ, что хотите удалить строку из таблицы?",<br/>
"Осторожно. Удаление строки из таблицы", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);<br/>
switch (result)<br/>
{<br/>
case DialogResult.Yes:<br/>
{<br/>
SqlConnection connection = new SqlConnection("server=ROOT-ПК\\SQLEXPRESS; database=edik; uid=sa; pwd=123321");<br/>
connection.Open();<br/>
SqlCommand cmdDel = new SqlCommand("DELETE FROM edik_1 WHERE FeedID = @FeedID", connection);<br/>
SqlParameter param = new SqlParameter();<br/>
param.DbType = DbType.Int32;<br/>
param.ParameterName = "@FeedID";<br/>
// MessageBox.Show(dataGridView1.CurrentRow.Cells[0].Value.ToString());<br/>
<br/>
//0 - это первая ячейка в текущей строке грида<br/>
<br/>
param.Value = dataGridView1.CurrentRow.Cells[0].Value;<br/>
cmdDel.Parameters.Add(param);<br/>
byte count = 0;<br/>
<br/>
try<br/>
{<br/>
count = (byte)cmdDel.ExecuteNonQuery();<br/>
}<br/>
catch (Exception ex)<br/>
{<br/>
MessageBox.Show(ex.ToString());<br/>
}<br/>
finally<br/>
{<br/>
if ((connection != null))<br/>
{<br/>
connection.Close();<br/>
}<br/>
}<br/>
<br/>
if (count > 0)<br/>
{<br/>
dataGridView1.Rows.RemoveAt(dataGridView1.CurrentRow.Index);<br/>
}<br/>
<br/>
if (e.ColumnIndex == 3) dataGridView1.Rows.RemoveAt(e.RowIndex);<br/>
else if (e.ColumnIndex == 0)<br/>
{<br/>
/*---Парсинг---*/<br/>
XmlTextReader reader = new XmlTextReader((sender as DataGridView)[e.ColumnIndex, e.RowIndex].Value.ToString());<br/>
while (reader.Read())<br/>
{<br/>
switch (reader.Name)<br/>
{<br/>
case "title":<br/>
listBox1.Items.Add(reader.ReadString());<br/>
break;<br/>
case "link":<br/>
listBox1.Items.Add(reader.ReadString());<br/>
break;<br/>
case "pubDate":<br/>
listBox1.Items.Add(reader.ReadString());<br/>
listBox1.Items.Add("\n");<br/>
break;<br/>
}<br/>
} <br/>
<br/>
}<br/>
break;<br/>
}<br/>
<br/>
case DialogResult.No:<br/>
{<br/>
return;<br/>
}<br/>
}<br/>
<br/>
}<br/>
}<br/>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question