ASP.NET Tutorial/ADO.net Database/ODBC
Версия от 15:30, 26 мая 2010; (обсуждение)
Connection String for MySQL database
<%@ Page Language="C#" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.Odbc" %>
<script runat="server">
void Page_Load(object sender, EventArgs e) {
string ConnectionString = @"driver={MySQL ODBC 3.51 Driver};server=localhost;database=books;uid=user;pwd=letmein;";
string CommandText = "select * from employee";
OdbcConnection myConnection = new OdbcConnection(ConnectionString);
OdbcCommand myCommand = new OdbcCommand(CommandText, myConnection);
myConnection.Open();
DataGrid1.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
DataGrid1.DataBind();
myConnection.Close();
}
</script>
<html>
<head>
</head>
<body >
<form runat="server">
<asp:datagrid id="DataGrid1" runat="server" EnableViewState="False">
<HeaderStyle font-bold="True"></HeaderStyle>
<ItemStyle backcolor="#DEDFDE"></ItemStyle>
</asp:datagrid>
</form>
</body>
</html>