我是初学者,有一个基本问题。我最近将此代码添加到我的方法中
if (dt.Rows.Length > 0)
但是,我返回错误:“System.Data.DataRowCollection”不包含“长度”的定义,并且找不到接受“System.Data.DataRowCollection”类型的第一个参数的扩展方法“长度”(您是否缺少 using 指令或程序集引用?),我不是说要为我编写代码(除非您想要 :),)但是如果有人能指出我正确的方向,那对您来说真是太棒了,也是您的好运.这里有一些代码可以提供帮助。
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Configuration;
public class Database
{
private string serverPCICUSTOM, serverPCI;
private string ConnectionStringPCICUSTOM, ConnectionStringPCI;
private SqlConnection connectionPCICUSTOM, connectionPCI;
private string trackingNumber;
private string soptype;
private string orderNumber;
public bool UpdateOrderToShipped(string order)
{
orderNumber = order;
string batch = ConfigurationManager.AppSettings["SuccessfulOrderBatch"];
string statement = "UPDATE SOP10100 SET BACHNUMB = '"+ batch +"' WHERE SOPNUMBE = @SOPNUMBE";
SqlCommand comm = new SqlCommand(statement, connectionPCI);
comm.Parameters.Add("SOPNUMBE", orderNumber);
try
{
comm.Connection.Open();
comm.ExecuteNonQuery();
comm.Connection.Close();
}
catch(Exception e)
{
comm.Connection.Close();
KaplanFTP.errorMsg = "Database error: " + e.Message;
}
statement = "SELECT SOPTYPE FROM SOP10100 WHERE SOPNUMBE = @SOPNUMBE";
comm.CommandText = statement;
SqlDataAdapter da = new SqlDataAdapter(comm);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Length > 0) //error here
{
comm.Connection.Open();
soptype = dt.Rows[0]["SOPTYPE"].ToString();
}
else
{
}
return true;
}
最佳答案
检查这个:
使用
if (dt.Rows.count> 0)
代替
if (dt.Rows.length> 0)
希望我的回答能帮助您解决问题。
关于c# - 'System.Data.DataRowCollection' 不包含 "Length"的定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7795796/