0

i've set up an userdefined connection string and now trying to populate a gridview using that,breakpoint shows connection string's fine..also no error,but surprisingly datatable is n't receiving any value..although data exists...what have i done wrong??

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
}

Class file:

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;         
 }
*/
3
  • Why did you do autogeneratecolumns=false? You either need to set that to true or add some markup defining your columns. Commented Feb 19, 2014 at 5:24
  • you sure the oradb = String.Concat(oradb, str); results into correct connection string??? Commented Feb 19, 2014 at 5:31
  • yes...the connection string's fine... Commented Feb 19, 2014 at 9:53

1 Answer 1

1

Try as per below, instead of returning connection string from function return Oracle Connection object and pass the same to Adapter.

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;
}
Sign up to request clarification or add additional context in comments.

2 Comments

sorry to reply that the datatable still isn't receiving any data...y'r logic seems brilliant...but for some unknown reason it doesn't populate the grid...is it running @ y'r end??
Have you set AutoGenerateColumns = True ?? Please check

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.