Subject: Connect to DB
Posted By: RaZorCleaN Post Date: 9/23/2003 3:59:02 AM
I am a Noob on ASP.NET, I am doing a connection to a DB but i dont understand it quite...the mdb file is in the sam folder bu only get a error mess ! do I have to insall a DB, how do I connect to mysql???

Would be super if someone could help me...

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script language="C#" runat="server">
void Page_Load(object sender, EventArgs e)
{ 
  OleDbConnection objConnection;
  OleDbDataAdapter objCommand;  
  string strConnect; 
  string strCommand; 
  DataSet DataSet1 = new DataSet();
 
  strConnect =  @"Provider=Microsoft.Jet.OLEDB.4.0;";

folder this sample is from asp.net with c#
  strConnect += @"Data Source=C:\Program Files\Microsoft.NET\FrameworkSDK\";
  strConnect += @"Samples\quickstart\aspplus\samples\grocertogo\data";
  strConnect += @"\grocertogo.mdb;";
  
  strConnect += "Persist Security Info=False";

  strCommand = "SELECT ProductName, UnitPrice FROM products";
  objConnection = new OleDbConnection(strConnect);
  objCommand = new OleDbDataAdapter(strCommand, objConnection);
  objCommand.Fill(DataSet1, "products");
  DataGrid1.DataSource=DataSet1.Tables["Products"].DefaultView;
  DataGrid1.DataBind();
}
</script>
<html>
<head>
<title>Data Grid Control example</title>
</head>
<body>
<asp:DataGrid id="DataGrid1" runat="server"  />
</body>
</html>


//RaZ
www.razorclean.com

Go to topic 4408

Return to index page 1040
Return to index page 1039
Return to index page 1038
Return to index page 1037
Return to index page 1036
Return to index page 1035
Return to index page 1034
Return to index page 1033
Return to index page 1032
Return to index page 1031