[已解决] C#通过csv设置dtable列名 [英] [Solved]C# setting dtable column names via csv

查看:259
本文介绍了[已解决] C#通过csv设置dtable列名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我的大部分编程都是使用C ++进行的,因此我使用的是C#中的MS VS2008构建,因此非常绿色.我目前正在使用FTP组件下载名称,电话号码,设备类型,状态等的csv,然后使用OLEdb适配器将其解析为表格.变成我的问题的是第一行信息未设置为列名.相反,我在gridview中得到的是F1,F2等.然后将csv的第一行显示在顶部.我的第二个问题是在第一行中没有数字的列标题(即数字列)不会出现.
所以我的前几行看起来像这样(其中f1,f2是表本身上方的列的标题.

--F1 ----------- F2 ---------- F3 ----------- F4 ---
名称------(空白)---设备类型-状态-
myname --- 1234567-智能手机-活动-
我如何获取姓名,电话号码,设备类型,状态,直到F1,F2等位置?这可能会解决我的第二个问题,但是为了澄清起见,如何在不将数字转换为字符串的情况下出现电话号码"一词?

这是CSV的示例
名称,电话号码,设备类型,状态
我的名字",1234567,SmartPhone,active

I am using MS VS2008 building in C# and rather green since most of my programming was done in C++. I''m currently using an FTP component to download a csv of names,phone numbers,device type, status, ect and then parse it into a table using the OLEdb adapter. What becomes my issue is that the first row of information isn''t set as the column names. Instead what i get in my gridview is F1,F2, ect. and then the first row of the csv is brought in at the top. My second issue regarding that is that in the first row the column titles that have numbers (ie the number column) the title doesn''t come up.
so my first few rows would look like this (where f1,f2 are the titles of the columns above the table itself.

--F1-----------F2----------F3-----------F4---
Name ------ (blank) --- device type -- status --
myname ---1234567 -- SmartPhone -- active --
how do i get the name, phone number, device type, status up into where the F1,F2 ect are? This may solve my second issue, but for the sake of clarification how do I get the word Phone Number to come up without turning the number into a string?

here is a sample of the CSV
Name,PhoneNum,Device Type,Status
"my name",1234567,SmartPhone,active

推荐答案

在您的OLEDB连接字符串中添加HDR=YES.
In your OLEDB connection string add HDR=YES.


这篇关于[已解决] C#通过csv设置dtable列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆