In my C# ASP.Net project I am using a xsd dataset to link to my database. I want to create a function return a single row from the strongly typed datatable but I’m running into a little difficulty doing this in C#. I have previously done this in VB.Net successfully using the code:
Public Function dr() As DataSet1.UsersRow
Dim ta As New DataSet1TableAdapters.UsersTableAdapter
Dim dt As DataSet1.UsersDataTable = ta.GetData
Return dt.Rows(0)
End Function
My C# version of the code is:
public DataSet1.UsersRow dr()
{
DataSet1TableAdapters.UsersTableAdapter ta = new DataSet1TableAdapters.UsersTableAdapter();
DataSet1.UsersDataTable dt = ta.GetData;
return dt.Rows(0);
}
I get the error Cannot implicitly convert type ‘System.Data.DataRow’ to ‘MyProject.DataSet1.UsersRow’. An explicit conversion exists (are you missing a cast?)
How can I return my strongly typed row in C#
You should be able to get it strongly typed using
dt[0];