'System.Data.Common.DbDataAdapter.Fill(System.Data.DataTable)' 的最佳重载方法匹配包含一些无效参数
The best overloaded method match for 'System.Data.Common.DbDataAdapter.Fill(System.Data.DataTable)' has some invalid arguments
我正在尝试从 oracle 数据库中获取数据。我收到此错误 The best overloaded method match for 'System.Data.Common.DbDataAdapter.Fill(System.Data.DataTable)' has some invalid arguments
这是我的个人资料class
public class Profile
{
public string PROF_TEXT {set; get;}
public string PROF_EMPL {set; get;}
public string PROF_NNAM {set; get;}
public string PROF_FNAM {set; get;}
public string PROF_MNAM {set; get;}
public string PROF_PADD {set; get;}
public string PROF_RADD {set; get;}
public string PROF_PPHN {set; get;}
public string PROF_HPHN {set; get;}
public string PROF_PNID {set; get;}
public string PROF_MAIL {set; get;}
public string PROF_REFR {set; get;}
public string PROF_RMRK {set; get;}
public string PROF_GEND {set; get;}
public string PROF_MARD {set; get;}
public string PROF_ACTV { set; get; }
}
second class ProfileDB 用于连接数据库
public class ProfileDB
{
private OracleConnection conn;
private OracleCommand cmd;
private OracleDataAdapter oda;
private DataSet ds;
string strComm;
public List<Profile> ListAll()
{
try
{
List<Profile> lst = new List<Profile>();
conn = new OracleConnection(clsConnection.ConnectionSave);
conn.Open();
strComm = "SELECT * FROM PROFILE";
cmd = new OracleCommand(strComm, conn);
oda = new OracleDataAdapter(cmd);
oda.Fill(lst);
conn.Dispose();
conn.Close();
return lst;
}
catch
{
return null;
}
}
}
和连接class
public class clsConnection
{
public OracleConnection oConn;
public clsConnection()
{
}
public static string ConnectionSave
{
get
{
string oradb = "Data Source=try; User Id=try; Password =try123";
return oradb;
}
}
}
我在此处遇到错误 oda.Fill(lst); 在标题中提及。这是数据库列
。
我是 .net 的新手。我想使用 classes 连接数据库。圆顶可以帮助我解决错误。我知道这很愚蠢,但作为新人无法获得解决方案。先感谢您。请让我知道任何其他需要的信息。
您不能使用Fill
方法来填充List<T>
,您必须向它传递一个DataSet
对象。然后您可以查询该对象的表(或遍历它)并加载您的 List
。像这样:
oda.Fill(ds);
conn.Dispose();
conn.Close();
foreach (DataRow row in ds.Tables[0].Rows)
{
lst.Add(/* however you create your profile instance */);
}
我正在尝试从 oracle 数据库中获取数据。我收到此错误 The best overloaded method match for 'System.Data.Common.DbDataAdapter.Fill(System.Data.DataTable)' has some invalid arguments
这是我的个人资料class
public class Profile
{
public string PROF_TEXT {set; get;}
public string PROF_EMPL {set; get;}
public string PROF_NNAM {set; get;}
public string PROF_FNAM {set; get;}
public string PROF_MNAM {set; get;}
public string PROF_PADD {set; get;}
public string PROF_RADD {set; get;}
public string PROF_PPHN {set; get;}
public string PROF_HPHN {set; get;}
public string PROF_PNID {set; get;}
public string PROF_MAIL {set; get;}
public string PROF_REFR {set; get;}
public string PROF_RMRK {set; get;}
public string PROF_GEND {set; get;}
public string PROF_MARD {set; get;}
public string PROF_ACTV { set; get; }
}
second class ProfileDB 用于连接数据库
public class ProfileDB
{
private OracleConnection conn;
private OracleCommand cmd;
private OracleDataAdapter oda;
private DataSet ds;
string strComm;
public List<Profile> ListAll()
{
try
{
List<Profile> lst = new List<Profile>();
conn = new OracleConnection(clsConnection.ConnectionSave);
conn.Open();
strComm = "SELECT * FROM PROFILE";
cmd = new OracleCommand(strComm, conn);
oda = new OracleDataAdapter(cmd);
oda.Fill(lst);
conn.Dispose();
conn.Close();
return lst;
}
catch
{
return null;
}
}
}
和连接class
public class clsConnection
{
public OracleConnection oConn;
public clsConnection()
{
}
public static string ConnectionSave
{
get
{
string oradb = "Data Source=try; User Id=try; Password =try123";
return oradb;
}
}
}
我在此处遇到错误 oda.Fill(lst); 在标题中提及。这是数据库列
我是 .net 的新手。我想使用 classes 连接数据库。圆顶可以帮助我解决错误。我知道这很愚蠢,但作为新人无法获得解决方案。先感谢您。请让我知道任何其他需要的信息。
您不能使用Fill
方法来填充List<T>
,您必须向它传递一个DataSet
对象。然后您可以查询该对象的表(或遍历它)并加载您的 List
。像这样:
oda.Fill(ds);
conn.Dispose();
conn.Close();
foreach (DataRow row in ds.Tables[0].Rows)
{
lst.Add(/* however you create your profile instance */);
}