我已經建立了一個用戶自定義的連接字符串填充和現在正試圖填充使用一個GridView,斷點顯示連接字符串的fine..also沒有錯誤,但令人驚訝的數據表爲n沒有收到任何價值..儘管數據存在...我做錯了什麼?的GridView不會與自定義連接字符串和自定義數據源
Default3.Aspx:
<td colspan="2" align="center">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
</asp:GridView>
</td>
Default3.Aspx.Cs:
protected void Page_Load(object sender, EventArgs e)
{
string con = OracleDatabase.connection();
String SelectCommand = "select * from EMP";
OracleDataAdapter adp = new OracleDataAdapter(SelectCommand, con);
DataTable dt = new DataTable();
adp.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
/*
OracleDatabase.gridpopulate(SelectCommand, GridView1);
GridView1.DataSource = OracleDatabase.gridpopulate(SelectCommand);
GridView1.DataBind();
*/
//i tried doing this by writting a function At class file also
}
類文件:
public static string connection()
{
oradb = ConfigurationManager.ConnectionStrings["ConnectionString"]
.ConnectionString;
string str = "Data Source="+db+";User ID="+userid+";Password="+password+";";
oradb = String.Concat(oradb, str);
con = new OracleConnection(oradb);
con.Open();
return oradb;
}
/*(function for gridpopulate)
public static void gridpopulate(string SelectCommand,GridView grid1)
{
string con =(ConfigurationManager.ConnectionStrings["ConnectionString"]
.ConnectionString);
con = String.Concat(con, str);
adp = new OracleDataAdapter(SelectCommand,con);
DataTable dt = new DataTable();
adp.Fill(dt);
grid1.DataSource = dt;
grid1.DataBind();
//return dt;
}
*/
你爲什麼要這樣做autogeneratecolumns = false?您需要將其設置爲true或添加一些用於定義列的標記。 – mason
你確定了'ORADB = String.Concat(ORADB,STR);'成果轉化爲正確的連接字符串??? –
是...連接字符串的罰款... – user2691165