Jeff Heilman
asked on
C# List conversion error Cannot convert from System.Collections.Generic.List to class
I'm hoping someone can help me understand what's going on here and what I have to do to correct it. I'm trying to upload a list of scanned data to a web service and keep getting the error: Argument 1: cannot convert from 'System.Collections.Generi c.List<Pro filesScan. WSTori.Cou ntDetails> ' to 'ProfilesScan.WSTori.Count Details[] I've tried converting the list to an Array to no avail. Here is the code:
if (NetworkCheck.IsInternet())
{
string path = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "LocalData.db3");
var tablelistout = new SQLiteConnection(path);
var list = tablelistout.Table<EOMCountsheet>();
var data = new List<string>();
List<CountDetails> invCountList = new List<CountDetails>();
foreach (var listing in list)
{
invCountList.Add(new CountDetails
{
InventoryCountSpecified = true,
InventoryCount = listing.InventoryCount,
Location = listing.Location,
Part = listing.Part,
UniqueStamp = listing.UniqueStamp,
UserID = listing.UserID,
});
}
List<CountDetails> countInfo = invCountList;
WSConnect.InsertCountDetails(countInfo);
}
EOMCountsheet class: public class EOMCountsheet
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public string Location { get; set; }
public int InventoryCount { get; set; }
public string Part { get; set; }
public string UserID { get; set; }
public string UniqueStamp { get; set; }
}
Code from my web service:[OperationContract]
string InsertCountDetails(List<CountDetails> countInfo);
[DataContract]
public class CountDetails
{
string location = "";
int inventorycount = 0;
string part = "";
string userid = "";
string uniquestamp = "";
[DataMember]
public string Location
{
get { return location; }
set { location = value; }
}
[DataMember]
public int InventoryCount
{
get { return inventorycount; }
set { inventorycount = value; }
}
[DataMember]
public string Part
{
get { return part; }
set { part = value; }
}
[DataMember]
public string UserID
{
get { return userid; }
set { userid = value; }
}
[DataMember] public int? ID { get; set; }
[DataMember]
public string UniqueStamp
{
get { return uniquestamp; }
set { uniquestamp = value; }
}
}
public string InsertCountDetails(List<CountDetails> countInfo)
{
var connString = ConfigurationManager.ConnectionStrings["ToriConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(connString);
con.Open();
var cmd = new SqlCommand(
"INSERT INTO tblCountSheet(Location, InventoryCount, Part, UserID, UniqueStamp) " +
"VALUES(@Location, @InventoryCount, @Part, @UserID, @UniqueStamp)", con);
foreach (CountDetails det in countInfo)
{
cmd.Parameters.AddWithValue("@Location", det.Location);
cmd.Parameters.AddWithValue("@InventoryCount", det.InventoryCount);
cmd.Parameters.AddWithValue("@Part", det.Part);
cmd.Parameters.AddWithValue("@UserID", det.UserID);
cmd.Parameters.AddWithValue("@UniqueStamp", det.UniqueStamp);
con.Open();
int result = cmd.ExecuteNonQuery();
//if (result == 1)
//{
// Message = "Success";
//}
//else
//{
// Message = "Error";
//}
}
con.Close();
return countInfo.ToString();
}
ASKER
Hi it_saige, thank you for your comment. I tried that again just for good measure and I still get the same error, Error CS1503 Argument 1: cannot convert from 'System.Collections.Generi c.List<Pro filesScan. WSTori.Cou ntDetails> ' to 'ProfilesScan.WSTori.Count Details[]' . This has me pretty baffled.
Where do you get that error message? What line?
-saige-
-saige-
ASKER
The error is here
public static string InsertCountDetails(List<CountDetails> countInfo)
{
return _wsTori.InsertCountDetails(countInfo); <<<<<countInfo is underlined in red.
}
Is that referencing the one in your web service code block above?
-saige-
-saige-
ASKER
Yes it is.
ASKER
public static class WSConnect
{
private static WSTori.WSToriService _wsTori = new WSTori.WSToriService();
//#region Web service Calls
public static string InsertCountDetails(List<Co untDetails > countInfo)
{
return _wsTori.InsertCountDetails (countInfo );
}
{
private static WSTori.WSToriService _wsTori = new WSTori.WSToriService();
//#region Web service Calls
public static string InsertCountDetails(List<Co
{
return _wsTori.InsertCountDetails
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you it_saige! It went through. Now to tackle the next problem, Unhandled Exception: System.Web.Services.Protoc ols.SoapEx ception: The connection was not closed. The connection's current state is open.
I appreciate your help, have a great weekend!
JeffH
I appreciate your help, have a great weekend!
JeffH
Open in new window
-saige-