Using Connection Strings in asp.net 1.1



Using Connection Strings in asp.net 1.1 First make sure you've defined the credentials of your connection string in the 'web.config' file. Click here for details

Then in your asp.net vb file you need to add the below at the top of the page:

At the very top of the page insert the following:-
<%@ Page Language="VB" ContentType="text/html" validateRequest=false ResponseEncoding="iso-8859-1" debug="True" %>
  <%@ Import Namespace="System.Data" %>
  <%@ Import Namespace="System.Data.SQLClient" %>
Then:
<script language="vb" runat="server">
 
sub Page_Load(sender as Object, e as EventArgs)
   If Not Page.IsPostBack then
     BindData()
   End If
  End Sub
  Sub BindData()
  Dim MyConnection22 As SQLConnection
  MyConnection22 = New SQLConnection (ConfigurationSettings.AppSettings("ConnectionString"))
  Dim sql As String
  sql="SELECT * FROM table_name"
  Dim resultsDataSet as New DataSet()
  Dim myDataAdapter as SqlDataAdapter = New SqlDataAdapter(sql, myConnection22)
  myDataAdapter.Fill(resultsDataSet)
  datagrid_name.DataSource = resultsDataSet
  datagrid_name.DataBind()
  End Sub
  </SCRIPT>
Now you can create the datagrid:
<asp:datagrid runat="server" id="datagrid_name" /></asp:datagrid> 


Send a link to this page via email Send a link to this page via email