[Mono-list] Databind to SQLServer
Jones, Larry
LJones@Lithonia.com
Thu, 15 May 2003 20:26:56 -0700
I still have problems databinding to SQLServer. Since I last posted this
problem I upgraded to RedHat 9.0 and Mono 0.24. Still doesn't work. Exact
same program works fine On MS .Net but not on mono. Heres the code:
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Page Language="C#" %>
<script runat="server">
public void Page_Load()
{
SqlDataReader reader;
string connectionString = "Server=SERVER;Database=pubs;User
ID=sa;Password=password";
SqlConnection dbcon;
dbcon = new SqlConnection(connectionString);
dbcon.Open();
SqlCommand dbcmd = dbcon.CreateCommand();
string sql =
"SELECT au_fname, au_lname " +
"FROM Authors";
dbcmd.CommandText = sql;
reader = dbcmd.ExecuteReader();
dgAuthors.DataSource = reader;
dgAuthors.DataBind();
reader.Close();
dbcon.Close();
}
</script>
<Html>
<Body>
<H2>Testing Sql</H2>
<form runat="server">
<asp:DataList ID="dgAuthors" runat="Server">
<ItemTemplate>
<%#
DataBinder.Eval(Container.DataItem, "au_lname") %>
</ItemTemplate>
</asp:DataList>
</form>
</Body>
</Html>
Any suggestions as to what is wrong would be appreciated.
Larry Jones
Hydrel/Lithonia Lighting