在C#中将数组元素存储到Access数据库中 [英] Storing Array Elements into Access Database in C#
本文介绍了在C#中将数组元素存储到Access数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下方法从文本文件中提取数据&将值存储在数组中 -
public class data
{
public string 日期,时间,磁场,深度;
public double lat,lon;
}
private void view_file_Load( object sender,EventArgs e)
{
string str;
列表< data> gd = new List< data>();
尝试
{
使用(StreamReader sr = new StreamReader( C:\\Windows \\ Temp\\op.txt))
{
string 行;
while ((line = sr.ReadLine())!= null )
{
string [] arr = line.Split( new char [] {' '},System.StringSplitOptions.RemoveEmptyEntries) ;
while (sr.Peek()> 0 )
{
string [] s = new string [] { };
char [] c = new char [] {' '};
str = sr.ReadLine();
arr = str.Split(c);
data d = new data();
d.date = arr [ 0 ];
d.time = arr [ 1 ];
d.lat = Convert.ToDouble(arr [ 3 ]);
d.lon = Convert.ToDouble(arr [ 4 ]);
d.depth = arr [ 7 ];
d.mag = arr [ 8 ];
}
现在我想存储那些数组值进入访问数据库,我该如何实现呢?
解决方案
而是将文本文件加载到数组中,使用JET 4.0将此文件直接读入Access数据库。 OLEDB驱动程序:使用ASP.NET将文本文件读入Access [ ^ ]
i have used the following to to extract data from a text file & store values in an array-
public class data
{
public string date, time, mag, depth;
public double lat, lon;
}
private void view_file_Load(object sender, EventArgs e)
{
string str;
List<data> gd = new List<data>();
try
{
using (StreamReader sr = new StreamReader("C:\\Windows\\Temp\\op.txt"))
{
string line;
while ((line = sr.ReadLine()) != null)
{
string[] arr = line.Split(new char[] { ' ' }, System.StringSplitOptions.RemoveEmptyEntries);
while (sr.Peek() > 0)
{
string[] s = new string[] { " " };
char[] c = new char[] { ' ' };
str = sr.ReadLine();
arr = str.Split(c);
data d = new data();
d.date = arr[0];
d.time = arr[1];
d.lat = Convert.ToDouble(arr[3]);
d.lon = Convert.ToDouble(arr[4]);
d.depth = arr[7];
d.mag = arr[8];
}
now i want to store those array values into access database, how do i achieve this?
解决方案
Instead loading text file into array, read this file direct into Access database using JET 4.0. OLEDB drivers: Reading Text files into Access with ASP.NET[^]
这篇关于在C#中将数组元素存储到Access数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文