Use OdbcDataAdapter to fill a DataSet : OdbcDataAdapter « ADO.net Database « ASP.NET Tutorial






<%@ Page Language="C#" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.Odbc" %>
<script runat="server">
    void Page_Load(object sender, EventArgs e)
    {
       string ConnectionString = Convert.ToString(ConfigurationSettings.AppSettings["MySQLConnectString"]);
       string CommandText = "SELECT * FROM Publisher";

       OdbcConnection myConnection = new OdbcConnection(ConnectionString);
       OdbcCommand myCommand = new OdbcCommand(CommandText, myConnection);

       OdbcDataAdapter myAdapter = new OdbcDataAdapter();
       myAdapter.SelectCommand = myCommand;
       DataSet myDataSet = new DataSet();
       try {
          myConnection.Open();
          myAdapter.Fill(myDataSet);
       } catch (Exception ex) {
          throw (ex);
       } finally {
          myConnection.Close();
       }

       myGrid.DataSource = myDataSet;
       myGrid.DataBind();

    }

</script>
<html>
<head>
</head>
<body>
    <form runat="server">
        <asp:DataGrid id="myGrid" runat="server"></asp:DataGrid>
    </form>
</body>
</html>

File: Web.config

<configuration>
    <appSettings>
      <add key="MySQLConnectString"
           value="driver={MySQL ODBC 3.51 Driver};server=localhost;database=Books;uid=YourID;pwd=letmein;" />
    </appSettings>
</configuration>








18.19.OdbcDataAdapter
18.19.1.Use OdbcDataAdapter to fill a DataSet