到目前为止,我已经成功地从.dbf
文件中检索了数据,但是我仍然不知道如何将这些数据存储到数据库中。当前,我与SQL Server建立了连接,连接字符串名称为PortageleafPickupEntities1
,其中包含三列Address,SeasonType和NextPickupdate。
现在,此.dbf
数据具有每列的所有数据,只需将其转移到那里即可。
这是代码...
public HttpResponseMessage Post([FromBody]LeafPickup pickup )
{
string cadena = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = C:\\Users\\azib\\Desktop\\dfb; Extended Properties = dBASE IV; User ID = Admin; Password =";
string select = "Select * from sp18br ";
DataSet myDataSet = new DataSet();
OleDbConnection con = new OleDbConnection(cadena);
OleDbCommand myAccessCommand = new OleDbCommand(select, con);
OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(myAccessCommand);
con.Open();
myDataAdapter.Fill(myDataSet, "sp18br");
con.Close();
DataTableCollection dta = myDataSet.Tables;
foreach (DataTable dt in dta)
{
Console.WriteLine("Found data table {0}", dt.TableName);
}
Console.WriteLine("{0} rows in sp18br table", myDataSet.Tables["sp18br"].Rows.Count);
DataRowCollection dra = myDataSet.Tables["sp18br"].Rows;
foreach (DataRow dr in dra)
{
// Print the CategoryID as a subscript, then the Name:
Console.WriteLine("\n" + " {0} -- {1} -- {2} -- {3} -- {4} ", "\n" + dr[0], dr[1], dr[2], dr[3], dr[4]);
}
using (PortageLeafPickupEntities1 entities = new PortageLeafPickupEntities1())
{
entities.LeafPickups.Add(pickup);
entities.SaveChanges();
var message = Request.CreateResponse(HttpStatusCode.Created, pickup);
message.Headers.Location = new Uri(Request.RequestUri + pickup.ID.ToString());
return message;
}
}