web BAsed Management [英] web BAsed Management

查看:104
本文介绍了web BAsed Management的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  string  dsource =  @  C:\ Users \ Comma \Desktop \ Working ON\WebBasedData \WebBasedData \ Data \Attachments_20131219; 

// 将数据源路径放在连接字符串中,例如,如果你有csv文件D:\目录更改数据源= D:\
字符串 constr = @ Provider = Microsoft.Jet.OLEDB.4.0; Data Source = + dsource + < span class =code-string>; Extended Properties ='text; HDR = Yes; FMT = Delimited';;

尝试
{
txtFromDate1.Text = Convert.ToString( MMDDYY);
txtToDate1.Text = Convert.ToString( MMDDYY);
string fromdate = txtFromDate1.Text;
string todate = txtToDate1.Text;
string fromtime = DropDownList2.SelectedItem.Text;
string totime = DropDownList3.SelectedItem.Text;


con.ConnectionString = constr;

// 为命令对象创建实例
OleDbCommand cmd = new OleDbCommand();


cmd.Connection = con;
// 在以下查询中设置您的文件名
cmd.CommandText = select * from [fpyield&&& fromdate&&& fromtime];


// 打开Oledb连接以读取CSV文件
con.Open();

// 创建一个数据表来存储CSV文件中的数据
DataTable dt = new DataTable();

// 将数据加载到数据表中
dt.Load (cmd.ExecuteReader());

// 在Gridview中绑定数据
GridViewShow.DataSource = dt;
GridViewShow.DataBind();



HI我有可能不以这种方式读取我的CSV文件从[fpyield 12162013 0930]中选择但是我想要选择[fpyield differentdate differenttime]从下拉列表中选择不同的日期和时间.....谢谢

解决方案

这真是一团糟。你的ASP.NET网站无法在整个文件系统中看到,只能在网络根目录下。你的网站内是否有这条路径?



Convert.ToString(MMDDYY) ;



返回MMDDYY。这是非代码,浪费时间。你为什么要用它?



string fromdate = txtFromDate1.Text;



根据定义,这不是日期,而是MMDDYY。



cmd.CommandText =select * from [fpyield && fromdate && fromtime];



这不是选择fromdate的值或从时间。它选择常数值fromda te和fromtime。这是你的意思吗?



从[fpyield 12162013 0930]中选择



这不是你的意思正在做,甚至远程。我建议你学习如何使用你的调试器,这样你就可以看到你的代码在做什么,以及它与你的期望有什么不同。


参见使用OleDb导入文本文件(选项卡,CSV,自定义) [ ^ ]。

string dsource = @"C:\Users\Comma\Desktop\Working ON\WebBasedData\WebBasedData\Data\Attachments_20131219";

//Put your datasource path in the connection string for example if you have csv files in D:\ directory change datasource= D:\
string constr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + dsource + ";Extended Properties='text;HDR=Yes;FMT=Delimited';";

            try
            {
                txtFromDate1.Text = Convert.ToString("MMDDYY");
                txtToDate1.Text = Convert.ToString("MMDDYY");
                string fromdate = txtFromDate1.Text;
                string todate = txtToDate1.Text;
                string fromtime = DropDownList2.SelectedItem.Text;
                string totime = DropDownList3.SelectedItem.Text;


                con.ConnectionString = constr;

                //create instance for command object 
                OleDbCommand cmd = new OleDbCommand();
               

                cmd.Connection = con;   
                // set your file name in the below query
                cmd.CommandText = "select * from [fpyield && fromdate && fromtime ]" ;
                
  
                //Open Oledb Connection to read CSV file 
                con.Open();

                //Create one datatable to store data from CSV file
                DataTable dt = new DataTable();

                // Load Data into the datatable 
                dt.Load(cmd.ExecuteReader());
           
                //Bind data in the Gridview
                GridViewShow.DataSource = dt;
                GridViewShow.DataBind();


HI is it possible for me not to read my CSV file in this way "select from [fpyield 12162013 0930] but i want to "select [fpyield differentdate differenttime]" the differentdate and time is selected from a dropdownlist..... thank you

解决方案

This is a real mess. Your ASP.NET website cannot see inside your whole file system, only under the web root. Is that path inside your web site ?

Convert.ToString("MMDDYY");

returns "MMDDYY". This is non code, a waste of time. Why are you using it ?

string fromdate = txtFromDate1.Text;

This is, by definition, not a date, but "MMDDYY".

cmd.CommandText = "select * from [fpyield && fromdate && fromtime ]" ;

This is not selecting the value of fromdate or fromtime. It's selecting the constant values "fromdate" and "fromtime". Is this what you meant ?

select from [fpyield 12162013 0930]

This is not what you are doing, not even remotely. I suggest you learn how to use your debugger, so you can see what your code is doing, and how it differs from what you expect.


See Using OleDb to Import Text Files (tab, CSV, custom)[^].


这篇关于web BAsed Management的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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