Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have those 2 methods in C# on asp.net:

DataTable dt;
        protected void Page_Load(object sender, EventArgs e)
        {            

                    //Fetch data from mysql database
                    MySqlConnection conn = new MySqlConnection("server=localhost;uid=root;
                         password=priya123;database=world;pooling=false;");
                    conn.Open();
                    string cmd = "select * from country limit 7";
                    MySqlDataAdapter dAdapter = new MySqlDataAdapter(cmd, conn);
                    DataSet ds = new DataSet();
                    dAdapter.Fill(ds);
                    dt=ds.Tables[0];
                    //Bind the fetched data to gridview
                    GridView1.DataSource = dt;
                    GridView1.DataBind();

        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if(e.CommandName.Equals("detail"))
            {
                int index = Convert.ToInt32(e.CommandArgument);
                string code = GridView1.DataKeys[index].Value.ToString();

                    IEnumerable<DataRow> query = from i in dt.AsEnumerable()
                                      where i.Field<String>("Code").Equals(code)
                                       select i;
                    DataTable detailTable = query.CopyToDataTable<DataRow>();
                    DetailsView1.DataSource = detailTable;
                    DetailsView1.DataBind();

            }
        }

now I want to use SQL SERVER. I create a LINQ with DBML.. and have object called 'sdb' with the DataContext. I try to do change it with Lambda expression, but Got an error that the selected row from the lambda is not 'IEnumerable'. how can I casting that to SQL SERVER objects?

thanks!

share|improve this question

closed as unclear what you're asking by usr, Bridge, BobTheBuilder, Mansfield, jadarnel27 Jan 16 at 15:02

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

    
Why not just change the MySql* ADO.NET objects to Sql*? –  Michael Perrenoud Jan 16 at 13:54
    
Yes that what I want. but which of them should I change? –  user3167150 Jan 16 at 13:56

1 Answer 1

up vote 0 down vote accepted

You just need to change from MySql* to Sql*, on every ADO.NET object:

DataTable dt;
protected void Page_Load(object sender, EventArgs e)
{            
    //Fetch data from mysql database
    SqlConnection conn = new SqlConnection("server=localhost;uid=root;
         password=priya123;database=world;pooling=false;");
    conn.Open();
    string cmd = "select * from country limit 7";
    SqlDataAdapter dAdapter = new SqlDataAdapter(cmd, conn);
    DataSet ds = new DataSet();
    dAdapter.Fill(ds);
    dt=ds.Tables[0];
    //Bind the fetched data to gridview
    GridView1.DataSource = dt;
    GridView1.DataBind();
}

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if(e.CommandName.Equals("detail"))
    {
        int index = Convert.ToInt32(e.CommandArgument);
        string code = GridView1.DataKeys[index].Value.ToString();

        IEnumerable<DataRow> query = from i in dt.AsEnumerable()
                          where i.Field<String>("Code").Equals(code)
                           select i;
        DataTable detailTable = query.CopyToDataTable<DataRow>();
        DetailsView1.DataSource = detailTable;
        DetailsView1.DataBind();
    }
}
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.