解决方案 »

  1.   


    "select * from " +filename+ ""-》string.Format("select * from {0}",fileName)
      

  2.   

    错误 4 参数 1: 无法从“string”转换为“System.Data.SqlClient.SqlCommand”
      

  3.   


    [/code]
    这样直接替换还是会有问题的,那个类不支持啊

    那个类??什么错?
    错误 4 参数 1: 无法从“string”转换为“System.Data.SqlClient.SqlCommand” 
      

  4.   

    这样直接替换还是会有问题的,那个类不支持啊

    那个类??什么错?
    错误 4 参数 1: 无法从“string”转换为“System.Data.SqlClient.SqlCommand”  
      

  5.   

    SqlDataAdapter da = new SqlDataAdapter("select * from " +filename, con);
      

  6.   

    版主大大,您确定这样和我的select有差嘛
      

  7.   

    这样直接替换还是会有问题的,那个类不支持啊

    那个类??什么错?
    错误 4 参数 1: 无法从“string”转换为“System.Data.SqlClient.SqlCommand”  
    参考,
    http://msdn.microsoft.com/zh-cn/library/system.data.sqlclient.sqldataadapter(v=vs.110).aspx
      

  8.   

    这样直接替换还是会有问题的,那个类不支持啊

    那个类??什么错?
    错误 4 参数 1: 无法从“string”转换为“System.Data.SqlClient.SqlCommand”  
    参考,
    http://msdn.microsoft.com/zh-cn/library/system.data.sqlclient.sqldataadapter(v=vs.110).aspx

    好麻烦~~~
      

  9.   

    版主大大,您确定这样和我的select有差嘛
    我觉得有
    你写得不对
    adapter构造函数可以直接传入sqlcmd和conn
    但是你构造的时候vs好像把你那个理解成传SqlCommand类的构造了,所以才提示类型转换错误
      

  10.   

    string[] split = strLine.Split('\n');
    都是神马逻辑,这个东东后面根本没用上啊
    先确定你TXT里到底什么格式,按格式读出来
      

  11.   

    m_streamReader.ReadLine();
    这个仅仅是读一行文本,不是整个文件都读出来,里面怎么会有\n??
    aa[shu] = strLine;
                        shu++;
    这又是闹哪样,你把文本存到aa[0]里,可是后面用的全部都是aa[1]!!!
      

  12.   

    版主大大,您确定这样和我的select有差嘛
    我觉得有
    你写得不对
    adapter构造函数可以直接传入sqlcmd和conn
    但是你构造的时候vs好像把你那个理解成传SqlCommand类的构造了,所以才提示类型转换错误
    现在一直提示'from' 附近有语法错误
      

  13.   

     aa[shu] = strLine;
                        shu++;
                        strLine = m_streamReader.ReadLine();
                        string filename = aa[shu];
    简直神逻辑
    你不是应该先读一行文本,放aa里,然后使用,使用完shu++么你在循环外先读了一条文本,放到aa[0]里,然后shu++,变成aa[1],然后又去读文件,读完就在那放着没管
    然后用aa[1]这个空字符串去连数据库
    下一个循环将上次读到的文本放到了aa[1]里,然后又去读文件,然后用aa[2]连数据库
    简直有病
      

  14.   

    抱歉,激动了.
    问题是你这个错误犯的太低级了点.
    根本和xml文件,数据库,一点关系都没有.
      

  15.   

    把c:\\select.txt里面的内容贴出来看一下吧。
    在你的代码中,它里面的内容又作为数据库中的表名,又作为磁盘上的文件名,让我感觉很奇怪。
    只是打个比方啊,如果里面的内容是 c:\haonan.xml ,而你的数据库中的表名称也叫c:\haonan.xml 的话,那么你的SQL语句那里得写成"select * from [" +filename+ "]"
      

  16.   

    嗯,确实啊,我都没往下看了,前面问题就够多了
    SqlDataAdapter da = new SqlDataAdapter("select * from " +filename+ "", con);
    你把文件内容放到aa里,结果用filename去拼接SQL语句?
      

  17.   

    先把SQL语句打印出来,执行一下看看是否正确再说
      

  18.   

    lz,帮你整理一下需求
    有个select.txt的文件,里面放的是表名,内容类似于下面这样TableName1
    TableName2
    TableName3然后你希望把数据库里向对应的表的数据输出成以表名为文件名的xml文件对不?
    比如上面的select.txt,输出就是TableName1.xml, TableName2.xml, TableName3.xml
    这三个xml文件对不?
      

  19.   

    string strLine;
    string path = "c:\\select.txt";
    if (!File.Exists(path))
    return;String strCon = "Data Source=XXJSB-PC;Initial Catalog=master;Integrated Security=True";
    SqlConnection con = new SqlConnection(strCon);
    SqlDataAdapter da;
    DataSet ds;
    con.Open();
    using (sr = new StreamReader(pointPath, Encoding.Default, true))
    {
    while ((strLine = sr.ReadLine()) != null)
    {
            da = new SqlDataAdapter("select * from " +filename+ "", con);
    ds = new DataSet();
    da.Fill(ds);
    }
    }
    con.Close();
      

  20.   

    绑定在TreeView控件读取XML文件内容
      private XmlDocument NexusDocument = new XmlDataDocument();//定义一个XML文档对象
            private void BindingXML_Load(object sender, EventArgs e)
            {
                string filePath = "NexusPoint.xml";//定义一个变量保存XML文件的路径
                if(File.Exists(filePath))//当在指定路径下存在该文件时
                {
                    NexusDocument.Load(filePath);//加载该路径下的XML文件
                    RecursionTreeControl(NexusDocument.DocumentElement,treeView1.Nodes);//将加载完成的XML文件显示在TreeView控件中
                    treeView1.ExpandAll();//展开TreeView控件中的所有项
                }
            }
             /// <summary>
             /// RecursionTreeControl:表示将XML文件的内容显示在TreeView控件中
             /// </summary>
             /// <param name="xmlNode">将要加载的XML文件中的节点元素</param>
             /// <param name="nodes">将要加载的XML文件中的节点集合</param>
            private void RecursionTreeControl(XmlNode xmlNode,TreeNodeCollection nodes)
            {//CodeGo.net/
                foreach(XmlNode node in xmlNode.ChildNodes)//循环遍历当前元素的子元素集合
                {
                    string temp = (node.Value != null ? node.Value : (node.Attributes != null && node.Attributes.Count > 0) ? node.Attributes[0].Value : node.Name);//表示TreeNode节点的文本内容
                    TreeNode new_child = new TreeNode(temp);//定义一个TreeNode节点对象
                    nodes.Add(new_child);//向当前TreeNodeCollection集合中添加当前节点
                    RecursionTreeControl(node,new_child.Nodes);//调用本方法进行递归
                }
            }