How To Update A Datatable In Vb.net
[RESOLVED] update specific column in a data row of a data table
How-do-you-do,Given the xml file and asp.cyberspace code:
Code:
<?xml version="i.0" standalone="yes"?> <Logs> <Indexer> <keyword>books</keyword> <url>www1</url> <occurence>1</occurence> </Indexer> <Indexer> <keyword>stone</keyword> <url>www2</url> <occurence>one</occurence> </Indexer> <Indexer> <keyword>tape</keyword> <url>www3</url> <occurence>1</occurence> </Indexer> <Indexer> <keyword>home</keyword> <url>www4</url> <occurence>i</occurence> </Indexer> <Indexer> <keyword>sand</keyword> <url>www5</url> <occurence>1</occurence> </Indexer> <Indexer> <keyword>books</keyword> <url>www6</url> <occurence>1</occurence> </Indexer> <Indexer> <keyword>price</keyword> <url>www7</url> <occurence>one</occurence> </Indexer> <Indexer> <keyword>books</keyword> <url>www8</url> <occurence>1</occurence> </Indexer> <Indexer> <keyword>record</keyword> <url>www9</url> <occurence>1</occurence> </Indexer> <Indexer> <keyword>jeans</keyword> <url>www10</url> <occurence>1</occurence> </Indexer> <Indexer> <keyword>rail</keyword> <url>www11</url> <occurence>ane</occurence> </Indexer> <Indexer> <keyword>price</keyword> <url>www12</url> <occurence>one</occurence> </Indexer> </Logs>
asp.internet code Code:
protected void Page_Load(object sender, EventArgs e)
{
DataSet ds = new DataSet("Logs");
cord[] words ={"books", "rock","tape","home","sand","books",
"price", "books","tape","jeans","rail",
"price"};
string[] url = {"www1","www2","www3","www4","www5",
"www6","www7","www8","www9","www10",
"www11","www12"};
DataTable dt = new DataTable("Indexer");
DataColumn col1 = new DataColumn("keyword");
DataColumn col2 = new DataColumn("url");
DataColumn col3 = new DataColumn("occurence");
dt.Columns.AddRange(new DataColumn[] { col1, col2, col3 });
DataColumn[] pri = new DataColumn[i]; //set principal key
pri[0] = dt.Columns[0];
dt.PrimaryKey = pri;
for (int i = 0; i < words.Length; i++)
{
//DataRow dr = dt.Rows.Detect(words[i]);
//if (dt.Rows.Count > 0)
//{
//foreach (DataRow dr in dt.Rows)
//{
// if ((cord)(dr["keyword"]) != words[i])
// {
DataRow dr2 = dt.NewRow();
dr2["keyword"] = words[i];
dr2["URL"] = url[i];
dr2["occurence"] = i;
dt.Rows.Add(dr2);
// }
//}//end foreach
//}
}//end for loop
//bind the dataset to the gridview and salve to xml file
ds.Tables.Add(dt);
this.GridView1.DataSource = ds.Tables["Indexer"].DefaultView;
this.GridView1.DataBind();
ds.WriteXml(@"c:\sampleData.xml");
}
}
How do i change the asp.net lawmaking so that if the same keyword in the datatable is found it volition change value of occurence past calculation 1 instead of calculation another element with the same keyword?Notation: How practise I trap if the data table has a primary key?
or a data table has no main cardinal?My instance sets the starting time cavalcade as a primary primal
If the datatable has been successfully updated, the right output (xml file) or gridview should be similar this..
Lawmaking:
<?xml version="1.0" standalone="yes"?> <Logs> <Indexer> <keyword>books</keyword> <url>www1</url> <occurence>3</occurence> </Indexer> <Indexer> <keyword>rock</keyword> <url>www2</url> <occurence>1</occurence> </Indexer> <Indexer> <keyword>record</keyword> <url>www3</url> <occurence>2</occurence> </Indexer> <Indexer> <keyword>home</keyword> <url>www4</url> <occurence>1</occurence> </Indexer> <Indexer> <keyword>sand</keyword> <url>www5</url> <occurence>1</occurence> </Indexer> <Indexer> <keyword>price</keyword> <url>www7</url> <occurence>two</occurence> </Indexer> <Indexer> <keyword>jeans</keyword> <url>www10</url> <occurence>1</occurence> </Indexer> <Indexer> <keyword>track</keyword> <url>www11</url> <occurence>1</occurence> </Indexer> </Logs>
Promise my queries are clear...Greg
Source: https://www.vbforums.com/showthread.php?531051-RESOLVED-update-specific-column-in-a-data-row-of-a-data-table
Posted by: michaelmathe1943.blogspot.com
0 Response to "How To Update A Datatable In Vb.net"
Post a Comment