hi friends..
how to insert a value in a datatable during runtime..(ex;hi)
i want coding for that in vb..
i am doing this in windows application..
its urgent..
regards
gopal
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Rajendra DeopuraPosted Nov 26, 2008, 11:59 PM
The following code helps you to add new row in a datatable at run time :
Dim ds As New DataSet
Dim dt As New DataTable("Student")
Dim dc1 As New DataColumn("FirstName",System.Type.GetType("String"))
Dim dc2 As New DataColumn("LastName", System.Type.GetType("String"))
dt.Columns.Add(dc1)
dt.Columns.Add(dc2)
ds.Tables.Add(dt)
Dim table As DataTable = ds.Tables(0)
Dim row As DataRow = table.NewRow
row(0) = "Rajendra"
row(1) = "Deopura"
dt.Rows.Add(row)
Blocked AccountPosted Nov 26, 2008, 11:03 PM
Hi,
By using this code u can add the text during runtime.
DataSet tempDS = ds1;
DataColumn dcQuestionStatus = new DataColumn("QuestionStatus", typeof(string));
DataColumn dcGivenAnswer = new DataColumn("GivenAnswer", typeof(string));
DataColumn dcAnswerStatus = new DataColumn("AnswerStatus", typeof(string));
tempDS.Tables[0].Columns.Add(dcQuestionStatus);
tempDS.Tables[0].Columns.Add(dcGivenAnswer);
tempDS.Tables[0].Columns.Add(dcAnswerStatus);
foreach (DataRow row in tempDS.Tables[0].Rows)
{
row["QuestionStatus"] = "NoStatus";
row["GivenAnswer"] = "";
row["AnswerStatus"] = "";
}
Happy Coding!!