I am a beginner and have a basic question. I recently added this code to my method
if (dt.Rows.Length > 0)
However, I return the error: ‘System.Data.DataRowCollection’ does not contain a definition for ‘Length’ and no extension method ‘Length’ accepting a first argument of type ‘System.Data.DataRowCollection’ could be found (are you missing a using directive or an assembly reference?), Im not saying to code this for me (unless you want to :), ) but if someone could point me into the right direction, that would be awesome and good fortune to you. Here is some code to help.
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;
}
Check this:
use
if (dt.Rows.count> 0)instead of
if (dt.Rows.length> 0)Hope my answer helps you to solve your problem.