求帮助,求大神,分全给了 C# 数据xml读取 .net 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 以上各位,没别的意思,请看清楚再回答,只是一个接口,现在写了一部分,改改动动,搞不明白了,从来没做过开发,也慢慢知道这就是一个接口而已,业务层,实际传输都不用考虑。简单说:按那个xml格式,组织出来一个字符串,判断一下是增加还是更新,然后调用更新或增加,最后写个方法,自己测一下能传输数就行(测试可以写个web,可以写个winform)这是这两天从一点没接触,慢慢摸索出来的。没人要功能,更没人要系统,钱?猪八戒?那是要系统,要全部开发,好不?各位看清楚好吗?我这里就是一个接口代码。都知道从基础学习,只是急需要,对于一个没有开发概念,开发工具否没见过的人来讲,请问一两天可以吗?你们都是开发人员,都知道程序员怎么成长起来的,正是因为如此,才求助一下这些程序员大侠。一个个都说没那么难,可又说全部代码别想了。如果时间充分,我从头开始学,学上几个月再做,我也知道简单了。我说了,不能做没关系,帮不了忙也没关系,就不要回复了,赚个积分,再数落人两句,很有意思吗? 楼主,这边都是帮忙解决问题,或是提供思路的。你这种情况问自己身边的同事或朋友比较靠谱些。再不行就自己google去吧。 XmlDocument解析请求ADO.NET等处理数据 根据的的xml 设计出来一个model序列化和反序列化 namespace CRM_XML_Test{ public partial class _Default : System.Web.UI.Page { public string insertCRMxml(string repID, string orgID, string name, string sex, string lastName, string firstName, string country, string zipCode, string city, string street) { string xml = "<request><insert><fields><RepUser><RepID>" + repID + "</RepID><OrgGrpID>" + orgID + "</OrgGrpID><Name>" + name + "</Name>" + "<Sex>" + sex + "</Sex><LastName>" + lastName + "</LastName><FirstName>" + firstName + "</FirstName><Country>" + country + "</Country>" + "<ZipCode>" + zipCode + "</ZipCode><City>" + city + "</City><Street>" + street + "</Street></RepUser></fields></insert></request>"; return xml; } public string updateCRMxml(string repID, string orgID, string name, string sex, string lastName, string firstName, string country, string zipCode, string city, string street) { string xml = "<request><update><tables><table tablename='RepUser'/></tables><condition><cond tablename='RepUser' fieldname='RepID' op='=' value='88'/>" + "</condition><fields><RepUser><RepID>" + repID + "</RepID><OrgGrpID>" + orgID + "</OrgGrpID><Name>" + name + "</Name>" + "<Sex>" + sex + "</Sex><LastName>" + lastName + "</LastName><FirstName>" + firstName + "</FirstName><Country>" + country + "</Country>" + "<ZipCode>" + zipCode + "</ZipCode><City>" + city + "</City><Street>" + street + "</Street></RepUser></fields></update></request>"; return xml; } protected void Page_Load(object sender, EventArgs e) { string s=""; string strXML=""; string connectionString = "Data Source=10.110.6.15.;Initial Catalog=DEV_UPDATE7;User id=UPDATE7;Password=Seven71!;"; string queryString = "select IfCanTransState from table"; using (SqlConnection connection = new SqlConnection(connectionString)) { SqlCommand command = new SqlCommand(queryString, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); try { while (reader.Read()) { s = reader[0].ToString().Trim(); } } finally { command.Dispose(); connection.Close(); } } if(s =="1") { strXML = updateCRMxml("repID", "orgID", "name", "sex", "lastName", "firstName", "country", "zipCode", "city", "street"); } else if(s =="2") { strXML = insertCRMxml("repID", "orgID", "name", "sex", "lastName", "firstName", "country", "zipCode", "city", "street"); } System.Net.WebClient wc = new System.Net.WebClient(); byte[] bs = System.Text.Encoding.Default.GetBytes(strXML); byte[] bsReturn = wc.UploadData("http://localhost:7421/Receive.aspx", bs); string strReturn = System.Text.Encoding.Default.GetString(bsReturn); Response.Write(strReturn); Response.End(); } }}这是写的,帮忙修正 using (SqlConnection connection = new SqlConnection(connectionString)) { SqlCommand command = new SqlCommand(queryString, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); try { while (reader.Read()) { s = reader[0].ToString().Trim(); } } finally { command.Dispose(); connection.Close(); } }改为using (SqlConnection connection = new SqlConnection(connectionString)) { SqlCommand command = new SqlCommand(queryString, connection); connection.Open(); object obj = command.ExecuteScalar(); if (obj != null && !(obj is DBNull)) { s = obj.ToString().Trim(); } connection.Close(); }另外,Receive.aspx这个页面的后台代码也贴过来看下 Receive.aspx代码:namespace CRM_XML_Test{ public partial class Receive : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { StreamReader reader = new StreamReader(Request.InputStream); String xml = reader.ReadToEnd(); FileStream fs = new FileStream(Server.MapPath("test.xml"), FileMode.Create); StreamWriter sw = new StreamWriter(fs); sw.Write(xml); sw.Close(); fs.Close(); Response.Write(xml); } }} Receive.aspx代码:namespace CRM_XML_Test{ public partial class Receive : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { StreamReader reader = new StreamReader(Request.InputStream); String xml = reader.ReadToEnd(); FileStream fs = new FileStream(Server.MapPath("test.xml"), FileMode.Create); StreamWriter sw = new StreamWriter(fs); sw.Write(xml); sw.Close(); fs.Close(); Response.Write(xml); } }} 你们是怎么考虑的?这两个xml的格式没统一?update里有tables和condition,insert里却没有? 不是同一个,是A系统数据往B系统传,传的时候在B系统的库里创建一个临时表,表里有那个字段,读取那个字段,来判断是增加还是更新。加一下我的QQ吧283759964 恩,好的,我这里有个QQ,上面有我的号,你登上,方便请教你,谢谢了QQ:1357391524 密码:qq662233 先把这俩xml的格式统一下吧,这样方便处理些 这个是不是用google的地图api啊? 读写web.config的简单问题? 请问sqldatasource 连接不上局域网数据库 怎么把一个数据库里某表的一个记录插入到另外一个数据库的表里? 未来的我能做设计吗? 嵌入ie的winform控件,通过remoting连接服务端,为什么第一次剧慢,以后就正常了,如何解决谢谢? 向服务器POST数据(参数+文件) 求助,如何让窗体显示在上一个窗体中央?? 窗体关闭? 如何从DataTable中获取从指定index开始count行数据的DataView? 一个JSON的问题 UNICODE 父类对象引用子类的实例,接口也可以吗?
没人要功能,更没人要系统,钱?猪八戒?那是要系统,要全部开发,好不?各位看清楚好吗?我这里就是一个接口代码。都知道从基础学习,只是急需要,对于一个没有开发概念,开发工具否没见过的人来讲,请问一两天可以吗?你们都是开发人员,都知道程序员怎么成长起来的,正是因为如此,才求助一下这些程序员大侠。一个个都说没那么难,可又说全部代码别想了。如果时间充分,我从头开始学,学上几个月再做,我也知道简单了。
我说了,不能做没关系,帮不了忙也没关系,就不要回复了,赚个积分,再数落人两句,很有意思吗?
你这种情况问自己身边的同事或朋友比较靠谱些。
再不行就自己google去吧。
ADO.NET等处理数据
序列化和反序列化
{
public partial class _Default : System.Web.UI.Page
{
public string insertCRMxml(string repID, string orgID, string name, string sex, string lastName, string firstName, string country,
string zipCode, string city, string street)
{
string xml = "<request><insert><fields><RepUser><RepID>" + repID + "</RepID><OrgGrpID>" + orgID + "</OrgGrpID><Name>" + name + "</Name>"
+ "<Sex>" + sex + "</Sex><LastName>" + lastName + "</LastName><FirstName>" + firstName + "</FirstName><Country>" + country + "</Country>"
+ "<ZipCode>" + zipCode + "</ZipCode><City>" + city + "</City><Street>" + street + "</Street></RepUser></fields></insert></request>";
return xml; } public string updateCRMxml(string repID, string orgID, string name, string sex, string lastName, string firstName, string country,
string zipCode, string city, string street)
{
string xml = "<request><update><tables><table tablename='RepUser'/></tables><condition><cond tablename='RepUser' fieldname='RepID' op='=' value='88'/>"
+ "</condition><fields><RepUser><RepID>" + repID + "</RepID><OrgGrpID>" + orgID + "</OrgGrpID><Name>" + name + "</Name>"
+ "<Sex>" + sex + "</Sex><LastName>" + lastName + "</LastName><FirstName>" + firstName + "</FirstName><Country>" + country + "</Country>"
+ "<ZipCode>" + zipCode + "</ZipCode><City>" + city + "</City><Street>" + street + "</Street></RepUser></fields></update></request>";
return xml; } protected void Page_Load(object sender, EventArgs e)
{
string s="";
string strXML=""; string connectionString = "Data Source=10.110.6.15.;Initial Catalog=DEV_UPDATE7;User id=UPDATE7;Password=Seven71!;";
string queryString = "select IfCanTransState from table";
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(queryString, connection);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
try
{
while (reader.Read())
{
s = reader[0].ToString().Trim();
}
}
finally
{
command.Dispose();
connection.Close();
}
}
if(s =="1")
{
strXML = updateCRMxml("repID", "orgID", "name", "sex", "lastName", "firstName", "country", "zipCode", "city", "street");
}
else if(s =="2")
{
strXML = insertCRMxml("repID", "orgID", "name", "sex", "lastName", "firstName", "country", "zipCode", "city", "street");
}
System.Net.WebClient wc = new System.Net.WebClient();
byte[] bs = System.Text.Encoding.Default.GetBytes(strXML);
byte[] bsReturn = wc.UploadData("http://localhost:7421/Receive.aspx", bs);
string strReturn = System.Text.Encoding.Default.GetString(bsReturn);
Response.Write(strReturn);
Response.End();
}
}
}
这是写的,帮忙修正
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(queryString, connection);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
try
{
while (reader.Read())
{
s = reader[0].ToString().Trim();
}
}
finally
{
command.Dispose();
connection.Close();
}
}改为using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(queryString, connection);
connection.Open();
object obj = command.ExecuteScalar();
if (obj != null && !(obj is DBNull))
{
s = obj.ToString().Trim();
}
connection.Close();
}另外,Receive.aspx这个页面的后台代码也贴过来看下
namespace CRM_XML_Test
{
public partial class Receive : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
StreamReader reader = new StreamReader(Request.InputStream);
String xml = reader.ReadToEnd();
FileStream fs = new FileStream(Server.MapPath("test.xml"), FileMode.Create);
StreamWriter sw = new StreamWriter(fs);
sw.Write(xml);
sw.Close();
fs.Close(); Response.Write(xml); }
}
}
namespace CRM_XML_Test
{
public partial class Receive : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
StreamReader reader = new StreamReader(Request.InputStream);
String xml = reader.ReadToEnd();
FileStream fs = new FileStream(Server.MapPath("test.xml"), FileMode.Create);
StreamWriter sw = new StreamWriter(fs);
sw.Write(xml);
sw.Close();
fs.Close();
Response.Write(xml);
}
}
}
恩,好的,我这里有个QQ,上面有我的号,你登上,方便请教你,谢谢了
QQ:1357391524 密码:qq662233