我如何编写读取DataRow的代码,但是如果在DataRow中存在的代码不存在,它只是跳过它并继续前进,例如:
string BarcodeIssueUnit;
if (dr_art_line["BarcodeIssueUnit"].ToString().Length <= 0)
{
BarcodeIssueUnit = "";
}
else
{
BarcodeIssueUnit = dr_art_line["BarcodeIssueUnit"].ToString();
}
Run Code Online (Sandbox Code Playgroud)
现在,列BarcodeIssueUnit可以属于表,但在某些情况下,表中不存在该列.如果它不在那里我读了它,我得到这个错误:
System.ArgumentException: Column `BarcodeIssueUnit`
does not belong to table Line.
Run Code Online (Sandbox Code Playgroud)
我只是想检查列是否正常,让我们看看值,如果不是,只需跳过该部分继续.
我想从SOAP消息中提取SOAP主体,我在SOAP主体中有一些数据,我必须在日期库中解析,所以这是代码:
public string Load_XML(string SoapMessage)
{
//check soap message
if (SoapMessage == null || SoapMessage.Length <= 0)
throw new Exception("Soap message not valid");
//declare some local variable
int iSoapBodyStartIndex = 0;
int iSoapBodyEndIndex = 0;
//load the Soap Message
//U?itaj string XML-a i pretvori ga u XML
XmlDocument doc = new XmlDocument();
try
{
doc.Load(SoapMessage);
}
catch (XmlException ex)
{
WriteErrors.WriteToLogFile("WS.LOAD_DOK_LoadXML", ex.ToString());
throw ex;
}
//search for the "http://schemas.xmlsoap.org/soap/envelope/" URI prefix
string prefix = string.Empty;
for (int i = 0; …Run Code Online (Sandbox Code Playgroud) 我有一个填充了samo数据/值的DataTable,我想从DataTable中读取数据并将其传递给字符串变量.
我有这个代码:
DataTable dr_art_line_2 = ds.Tables["QuantityInIssueUnit"];
Run Code Online (Sandbox Code Playgroud)
我有这样一个对手:
for (int i = 1; i <= broj_ds; i++ )
{
QuantityInIssueUnit_value => VALUE FROM DataTable
QuantityInIssueUnit_uom => VALUE FROM DataTable
}
Run Code Online (Sandbox Code Playgroud)
这可能吗?如果是,那么如何将数据从DataTable传递给那些变量?
谢谢!
有没有办法检查整数变量的长度,如果是长只是修剪它.我在数据库中有一个接受3个字符的字段,lenth是3.
所以它可以像使用字符串变量一样完成
例:
cust_ref = cust_ref.Length > 20 ? cust_ref.Substring(0, 19) : cust_ref;
Run Code Online (Sandbox Code Playgroud)
谢谢!
我一直在做一些Google搜索,只是在这个主题上取得了部分成功.我想知道是否有人可以建议使用C#进行HTTP POST以将XML发送到HTTP服务的示例.
我有一个asmx Web服务从数据库中提取数据,我将该数据保存到XML文档.现在我必须使用SOAP协议将该XML文档发送到HTTP服务.
我有这部分代码用于连接服务
WebRequest myReq = WebRequest.Create("https://WEB_URL");
System.Net.ServicePointManager.CertificatePolicy = new CertificatePolicyClass();
string username = "SOMETHING";
string password = "ELSE";
string usernamePassword = username + ":" + password;
CredentialCache mycache = new CredentialCache();
mycache.Add(new Uri("https://WEB_URL"), "Basic", new NetworkCredential(username, password));
myReq.Credentials = mycache;
myReq.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(new ASCIIEncoding().GetBytes(usernamePassword)));
WebResponse wr = myReq.GetResponse();
Stream receiveStream = wr.GetResponseStream();
StreamReader reader = new StreamReader(receiveStream, Encoding.UTF8);
string content = reader.ReadToEnd();
Run Code Online (Sandbox Code Playgroud)
那么有没有人有一个代码将XML文档发送到http服务,这部分我不知道怎么写,我不知道我在写跟踪,我相信它已经像这样去了一些
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
Run Code Online (Sandbox Code Playgroud)
有人可以帮助我!谢谢!
一个能DateTime值是NULL?
我有这个代码:
从这里我继承了我的变量
namespace Transakcija
{
public class Line
{
public System.DateTime DateOfProduction { get; set; }
}
}
Run Code Online (Sandbox Code Playgroud)
然后为每个循环:
foreach (var rw_det in dt_stavke.Rows)
{
var list = new List<Transakcija.Line>();
var l = new Transakcija.Line();
//DateOfProduction
if (rw_det["DPRO02"].ToString().Length <= 0)
{
l.DateOfProduction = default(DateTime);
}
else
{
l.DateOfProduction = new DateTime();
prod_date = rw_det["DPRO02"].ToString();
DateTime pro_date = DateTime.ParseExact(prod_date, "dd.MM.yyyy", CultureInfo.InvariantCulture);
string p_date = pro_date.ToString("yyyy-MM-dd");
l.DateOfProduction = DateTime.Parse(p_date);
}
}
Run Code Online (Sandbox Code Playgroud)
所以该值l.DateOfProduction必须为null.我试过这个:
DateTime? dt = …Run Code Online (Sandbox Code Playgroud) 一个问题...我在下面的示例代码...我要插入直接从数据row..I一些值到database..but不想使用variables.So我的问题是,是否有检查数据行中的值是否存在或者是否为null的方法,如果该值不存在,我必须插入null或者如果它为null则只插入null ...
这个例子:
myQuery = " INSERT INTO AGR3PL_CS (IDOC_NUM, PSEG_NUM, SEG_NUM, COMP01, GLNO01, NAME01) " +
" VALUES (" + Lidoc_num + ", '" +
PSEG_NUM + "','" +
SEG_NUM + "','" +
dr_art_custsuply["Id"] + "','" +
dr_art_custsuply["GLN"] + "','" +
dr_art_custsuply["Name"] + "')";
Run Code Online (Sandbox Code Playgroud)
这是我不想用的方式......
if (!dr_art_custsuply.Table.Columns.Contains("GLN") || dr_art_custsuply["GLN"].ToString().Length <= 0)
{
gln = "";
}
else
{
gln = dr_art_custsuply["GLN"].ToString();
}
Run Code Online (Sandbox Code Playgroud) 我还有一个问题
我有这个foreach声明:
foreach (DataRow dr_art_custsuply in ds.Tables["CustomerSupplier"].Rows)
{
//Podaci iz CustomerSupplier-a
//Id dobavlja?a
string cust_id;
if (!dr_art_custsuply.Table.Columns.Contains("Id"))
cust_id = "";
else if (dr_art_custsuply["Id"].ToString().Length <= 0)
cust_id = "";
else
cust_id = dr_art_custsuply["Id"].ToString();
//Naziv dobavlja?a
string name;
if (!dr_art_custsuply.Table.Columns.Contains("Name"))
name = "";
else if (dr_art_custsuply["Name"].ToString().Length <= 0)
name = "";
else
name = dr_art_custsuply["Name"].ToString();
//GLN
string gln;
if (!dr_art_custsuply.Table.Columns.Contains("GLN"))
gln = "";
else if (dr_art_custsuply["GLN"].ToString().Length <= 0)
gln = "";
else
gln = dr_art_custsuply["GLN"].ToString();
}
Run Code Online (Sandbox Code Playgroud)
我想要做的是检查是否ds.Tables ["CustomerSupplier"].行存在,如果没有为每个跳过这个,是不是通过代码,我试过这个
(!ds.Tables.Contains("CustomerSupplier"))
{
}
Run Code Online (Sandbox Code Playgroud)
但我得到了一个错误,所以帮忙帮忙,怎么写呢? …
我有一个大字符串要读,它总是不同的,但一个字总是一样的.这个词是MESSAGE,所以如果我的字符串阅读器遇到这个词,它必须将整个字符串写入光盘.我做了一些代码,但它没有工作,if段永远不会触发,这里有什么问题?
string aLine;
StringReader strRead = new StringReader(str);
aLine = strRead.ReadLine();
if (aLine == "MESSAGE")
{
//Write the whole file on disc
}
Run Code Online (Sandbox Code Playgroud)