Code
//注意如何给DataTable添加新行
DataRow newRow=dt.NewRow();//调用方法
.......
dt.Rows.Add(newRow);

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
SqlConnection conn = new SqlConnection("Server=zhuobin;uid=sa;pwd=zhuobin;database=Northwind");
string sql =@"select * from employees where country='UK'";
try
{
//Create the DataAdapter
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand(sql,conn);
//Create dataSet and fill it
DataSet ds = new DataSet();
da.Fill(ds,"employees");
//get the table reference
DataTable dt=ds.Tables["employees"];
//first name to be nullable
dt.Columns["firstname"].AllowDBNull = true;
//modify city in the first row
dt.Rows[0]["city"] = "Xuzhou";
//Add a row
DataRow newRow =dt.NewRow();
newRow["firstname"] = "Zhuo";
newRow["lastname"] = "bin";
newRow["titleofcourtesy"] = "123";
newRow["city"] = "Tengzhou";
newRow["country"] = "China";
dt.Rows.Add(newRow);
//display the data
foreach (DataRow row in dt.Rows)
{
Console.WriteLine("{0} {1} {2}",row["firstname"].ToString().PadRight(15),row["lastname"].ToString().PadLeft(25),row["city"]);
}
}
catch (SqlException ex)
{
Console.WriteLine("The error:{0}", ex.Message);
}
finally
{
conn.Close();
}
Console.ReadLine();
}
}
}