c#读取xml文件的问题~~ select数据string 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 "select * from " +filename+ ""-》string.Format("select * from {0}",fileName) 错误 4 参数 1: 无法从“string”转换为“System.Data.SqlClient.SqlCommand” [/code]这样直接替换还是会有问题的,那个类不支持啊那个类??什么错?错误 4 参数 1: 无法从“string”转换为“System.Data.SqlClient.SqlCommand” 这样直接替换还是会有问题的,那个类不支持啊那个类??什么错?错误 4 参数 1: 无法从“string”转换为“System.Data.SqlClient.SqlCommand” SqlDataAdapter da = new SqlDataAdapter("select * from " +filename, con); 版主大大,您确定这样和我的select有差嘛 这样直接替换还是会有问题的,那个类不支持啊那个类??什么错?错误 4 参数 1: 无法从“string”转换为“System.Data.SqlClient.SqlCommand” 参考,http://msdn.microsoft.com/zh-cn/library/system.data.sqlclient.sqldataadapter(v=vs.110).aspx 这样直接替换还是会有问题的,那个类不支持啊那个类??什么错?错误 4 参数 1: 无法从“string”转换为“System.Data.SqlClient.SqlCommand” 参考,http://msdn.microsoft.com/zh-cn/library/system.data.sqlclient.sqldataadapter(v=vs.110).aspx好麻烦~~~ 版主大大,您确定这样和我的select有差嘛我觉得有你写得不对adapter构造函数可以直接传入sqlcmd和conn但是你构造的时候vs好像把你那个理解成传SqlCommand类的构造了,所以才提示类型转换错误 string[] split = strLine.Split('\n');都是神马逻辑,这个东东后面根本没用上啊先确定你TXT里到底什么格式,按格式读出来 m_streamReader.ReadLine();这个仅仅是读一行文本,不是整个文件都读出来,里面怎么会有\n??aa[shu] = strLine; shu++;这又是闹哪样,你把文本存到aa[0]里,可是后面用的全部都是aa[1]!!! 版主大大,您确定这样和我的select有差嘛我觉得有你写得不对adapter构造函数可以直接传入sqlcmd和conn但是你构造的时候vs好像把你那个理解成传SqlCommand类的构造了,所以才提示类型转换错误现在一直提示'from' 附近有语法错误 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]连数据库简直有病 抱歉,激动了.问题是你这个错误犯的太低级了点.根本和xml文件,数据库,一点关系都没有. 把c:\\select.txt里面的内容贴出来看一下吧。在你的代码中,它里面的内容又作为数据库中的表名,又作为磁盘上的文件名,让我感觉很奇怪。只是打个比方啊,如果里面的内容是 c:\haonan.xml ,而你的数据库中的表名称也叫c:\haonan.xml 的话,那么你的SQL语句那里得写成"select * from [" +filename+ "]" 嗯,确实啊,我都没往下看了,前面问题就够多了SqlDataAdapter da = new SqlDataAdapter("select * from " +filename+ "", con);你把文件内容放到aa里,结果用filename去拼接SQL语句? 先把SQL语句打印出来,执行一下看看是否正确再说 lz,帮你整理一下需求有个select.txt的文件,里面放的是表名,内容类似于下面这样TableName1TableName2TableName3然后你希望把数据库里向对应的表的数据输出成以表名为文件名的xml文件对不?比如上面的select.txt,输出就是TableName1.xml, TableName2.xml, TableName3.xml这三个xml文件对不? 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(); 绑定在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);//调用本方法进行递归 } } 弱弱的请教截取字符的问题 进制转换 c#查询access数据库代码 checkbox如何被选中? c#创建xml节点的属性出错了,而且是很奇怪的错,请大家帮忙看看!! Property 与 attribute 的区别 问一个简单的一问题 c#2.0连接Oracle9i所引发Error while trying to retrieve text for error ORA-12541的问题。 求大神指教怎么让程序联网认证变成本地啊?? 请问sqlconnection 和 OleDbConnection有什么区别? c# messagebox 能不能做出滚动条? c#常量问题
"select * from " +filename+ ""-》string.Format("select * from {0}",fileName)
[/code]
这样直接替换还是会有问题的,那个类不支持啊
那个类??什么错?
错误 4 参数 1: 无法从“string”转换为“System.Data.SqlClient.SqlCommand”
那个类??什么错?
错误 4 参数 1: 无法从“string”转换为“System.Data.SqlClient.SqlCommand”
那个类??什么错?
错误 4 参数 1: 无法从“string”转换为“System.Data.SqlClient.SqlCommand”
参考,
http://msdn.microsoft.com/zh-cn/library/system.data.sqlclient.sqldataadapter(v=vs.110).aspx
那个类??什么错?
错误 4 参数 1: 无法从“string”转换为“System.Data.SqlClient.SqlCommand”
参考,
http://msdn.microsoft.com/zh-cn/library/system.data.sqlclient.sqldataadapter(v=vs.110).aspx
好麻烦~~~
我觉得有
你写得不对
adapter构造函数可以直接传入sqlcmd和conn
但是你构造的时候vs好像把你那个理解成传SqlCommand类的构造了,所以才提示类型转换错误
都是神马逻辑,这个东东后面根本没用上啊
先确定你TXT里到底什么格式,按格式读出来
这个仅仅是读一行文本,不是整个文件都读出来,里面怎么会有\n??
aa[shu] = strLine;
shu++;
这又是闹哪样,你把文本存到aa[0]里,可是后面用的全部都是aa[1]!!!
我觉得有
你写得不对
adapter构造函数可以直接传入sqlcmd和conn
但是你构造的时候vs好像把你那个理解成传SqlCommand类的构造了,所以才提示类型转换错误
现在一直提示'from' 附近有语法错误
shu++;
strLine = m_streamReader.ReadLine();
string filename = aa[shu];
简直神逻辑
你不是应该先读一行文本,放aa里,然后使用,使用完shu++么你在循环外先读了一条文本,放到aa[0]里,然后shu++,变成aa[1],然后又去读文件,读完就在那放着没管
然后用aa[1]这个空字符串去连数据库
下一个循环将上次读到的文本放到了aa[1]里,然后又去读文件,然后用aa[2]连数据库
简直有病
问题是你这个错误犯的太低级了点.
根本和xml文件,数据库,一点关系都没有.
在你的代码中,它里面的内容又作为数据库中的表名,又作为磁盘上的文件名,让我感觉很奇怪。
只是打个比方啊,如果里面的内容是 c:\haonan.xml ,而你的数据库中的表名称也叫c:\haonan.xml 的话,那么你的SQL语句那里得写成"select * from [" +filename+ "]"
SqlDataAdapter da = new SqlDataAdapter("select * from " +filename+ "", con);
你把文件内容放到aa里,结果用filename去拼接SQL语句?
有个select.txt的文件,里面放的是表名,内容类似于下面这样TableName1
TableName2
TableName3然后你希望把数据库里向对应的表的数据输出成以表名为文件名的xml文件对不?
比如上面的select.txt,输出就是TableName1.xml, TableName2.xml, TableName3.xml
这三个xml文件对不?
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();
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);//调用本方法进行递归
}
}