第一篇文章在這裏。我試圖創建一個從Oracle數據庫提取數據並返回一些表的網站。我能夠連接我的數據庫並創建了一個DataConnector
,它返回一個CodeDesc
對象的列表。我現在的主要問題是簡單地將數據顯示在屏幕上,最好是以下拉列表的形式顯示,但我現在使用GridView
。顯示查詢輸出到屏幕的C#asp.NET。錯誤:Oracle.DataAccess.dll中的'System.ArgumentException'
這裏是我的前端:
protected void Button1_Click(object sender, EventArgs e)
{
DataConnector dc = new DataConnector();
GridView2.DataSource = dc.getCodeTypes();
GridView2.DataBind();
}
當我點擊該按鈕時,會產生什麼和調試器只說「拋出異常:‘System.ArgumentException’在Oracle.DataAccess.dll」任何幫助將是讚賞。這是我第一次進行網絡開發,並且一直在努力爭取到這一點。我使用Visual Studio 2015年
後端:
//Create datatable to get info from db & return results
public List<CodeDesc> getCodeTypes()
{
try
{
OracleConnection con = new OracleConnection(connString);
con.Open();
string query = "select id, descr from code_desc where code_type_id = 0";
// Create the OracleCommand
OracleCommand cmd = new OracleCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
// Execute command, create OracleDataReader object
OracleDataReader reader = cmd.ExecuteReader();
List<CodeDesc> L = new List<CodeDesc>();
while (reader.Read())
{
CodeDesc c = new CodeDesc();
c.id = reader.GetInt32(0);
c.description = reader.GetString(1);
L.Add(c);
}
// Clean up
reader.Dispose();
cmd.Dispose();
con.Dispose();
System.Diagnostics.Debug.WriteLine(L);
return L;
}
catch (Exception ex)
{
// catch clause here...
}
}
CodeDesc:
public class CodeDesc
{
public int id { get; set; }
public string description { get; set; }
}
任何幫助將是巨大的。
看看你的錯誤的內部異常。它包含更多錯誤的詳細信息 – tomcater
您從不將查詢字符串設置爲要執行的CommandText。不好。 – Steve