2014-02-19 94 views
0

我已經建立了一個用戶自定義的連接字符串填充和現在正試圖填充使用一個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;   
} 
*/ 
+0

你爲什麼要這樣做autogeneratecolumns = false?您需要將其設置爲true或添加一些用於定義列的標記。 – mason

+0

你確定了'ORADB = String.Concat(ORADB,STR);'成果轉化爲正確的連接字符串??? –

+0

是...連接字符串的罰款... – user2691165

回答

1

嘗試按以下,插件從函數返回Oracle連接對象返回連接字符串,並通過相同的給適配器TEAD。

OracleConnection con = OracleDatabase.connection(); 

public static OracleConnection 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 con; 
} 
+0

抱歉地回答說,該數據表還沒有接收到任何數據... Y'R邏輯似乎輝煌......但由於一些未知的原因,它不填充網格...它運行@你結束了嗎? – user2691165

+0

你有設置的AutoGenerateColumns =真?請檢查 –