LiveWire Network Peer Answers Peer Support Teen Forums Tech Forums College Forums 688 users online 211191 members 1360 active today Advertise Here Sign In
TeenCollegeTechPhotos | Quizzes | LiveSecret | Memberlist | Dictionary | News | FAQ
Member Spotlight
WhiteTrashLilDarling
Interests: I like backroad riding, ATVs, and h...
Mood: Excited
You have 1 new message.
Emergency Help
Until you sign up you can't do much. Yes, it's free.

Sign Up Now
Membername:
Password:
Already have an account?
Invite Friends
Active Members
Groups
Contests
Moderators
9 online / 24 MPM
Fresh Topics
  LiveWire / Technical Forums / Programming & Application Development / Viewing Topic

SQL Express connection string ASP.NET v2.0
Currently using access, want to use SQL Express
Replies: 1Last Post April 25, 2007 4:41am by ArkiTecT101
Welcome to LiveWire!
We're Stronger Together.
Join the Community
Single page for this topic Email Print Favorite
( ArkiTecT101 )


Dairy Product Addict
Reply
Hi guys,

This is quite a difficult topic so I appreciate it if no one knows the answer, but I welcome all comments.

OK so I am messing around with web applications and databases. I have the knowledge to create a connection string to the access database but do not know how to access SQL Express database which is now part of Visual Web Developer (the development software I am using).

I have quickly drafted up an aspx page with its counterpart C# page as follows:

[ASPX PAGE]

<%@ Page Language="C#" AutoEventWireup="true" Inherits="addContractor" CodeFile="Default.aspx.cs" %>
<html>
<head runat="server">
   <title>Untitled Page</title>
</head>
<body>
   <form id="form1" runat="server">
   <div>
       Select a Category:
       <asp:DropDownList ID="list1" runat="server" OnSelectedIndexChanged="ContractorList" AutoPostBack="true">
           
       </asp:DropDownList><br />
       <br />
       <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label><br />
       <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br />
       <br />
       Contractor Description:
       <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
       Contractor Add1:        
       <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
       Contractor Add1:        
       <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox><br />
       Contractor Add1:        
       <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox><br />
       Contractor Add1:        
       <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox><br />
       Contractor Contact:    
       <asp:TextBox ID="TextBox6" runat="server"></asp:TextBox><br />
       <br />
       <asp:Button ID="Button1" runat="server" Text="Button" onClick="submitContractor"/></div>
   </form>
</body>
</html>

[C# PAGE]

using System;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


public partial class addContractor : System.Web.UI.Page
{
   protected void Page_Load(object sender, EventArgs e)
   {

       if (IsPostBack)
       {
           Label2.Text = "Category ID: " + list1.SelectedItem.Value;
       }
       else
       {

           Label2.Text = "Category ID: ";

           rtvContractorID();

           DateTime d = DateTime.Now;
           Label1.Text = d.ToString("d");

           OleDbConnection conn = new OleDbConnection();
           string connStr;
           connStr = "Provider=Microsoft.Jet.OLEDB.4.0;";
           connStr += "Data Source= " + Server.MapPath("App_Data/test.mdb");
           conn.ConnectionString = connStr;

           string queryString;
           queryString = "SELECT CategoryID, CategoryDesc FROM Category";
           OleDbCommand dbCommand = new OleDbCommand();
           dbCommand.CommandText = queryString;
           dbCommand.Connection = conn;

           conn.Open();

           OleDbDataReader dataReader = dbCommand.ExecuteReader();

           list1.DataSource = dataReader;
           list1.DataValueField = "CategoryID";
           list1.DataTextField = "CategoryDesc";
           list1.DataBind();


       }
   }

   public void ContractorList (object sender, EventArgs e)
         {
             Label2.Text = "Category ID: " + list1.SelectedItem.Value;

         }

   protected void rtvContractorID()
   {

       Guid ContractorID = Guid.NewGuid();
       Session["sContractorID"] = ContractorID;

   }

 
   protected void submitContractor(object sender, EventArgs e)
   {


       OleDbConnection conn;
       conn = new OleDbConnection();
       string connStr;
       connStr = "Provider=Microsoft.Jet.OLEDB.4.0;";
       connStr += "Data Source= " + Server.MapPath("App_Data/test.mdb");
       conn.ConnectionString = connStr;

       string queryString4;
       queryString4 = "insert into Contractor (ContractorID, CategoryID, ContDateAdded, ContDesc, Add1, Add2, Add3, Add4, ContactTel) values (";
       queryString4 += "'" + Convert.ToString(Session["sContractorID"]) + "', '";
       queryString4 += Convert.ToString(list1.SelectedItem.Value) + "', '";
       queryString4 += Label1.Text;
       queryString4 += "', '";
       queryString4 += TextBox1.Text;
       queryString4 += "', '";
       queryString4 += TextBox2.Text;
       queryString4 += "', '";
       queryString4 += TextBox3.Text;
       queryString4 += "', '";
       queryString4 += TextBox4.Text;
       queryString4 += "', '";
       queryString4 += TextBox5.Text;
       queryString4 += "', '";
       queryString4 += TextBox6.Text;
       queryString4 += "')";

       OleDbCommand dbCommand4 = new OleDbCommand();
       dbCommand4.CommandText = queryString4;
       dbCommand4.Connection = conn;
       conn.Open();
       dbCommand4.ExecuteNonQuery();

       conn.Close();
       Server.Transfer("default.aspx");

   }
}

So basically what I am asking is instead of connecting to an access database, I want to connect to an SQL express database. This requires modifcation in the connection string. If you know then please explain.

Thanks.



-------
Everyone needs something to believe in, so I believe i'll have another beer.www.kwearing.co.uk


9:13 am on April 20, 2007 | Joined: Jan. 2005 | Days Active: 331
Join to learn more about ArkiTecT101 United Kingdom | Straight Male | Posts: 1,255 | Points: 4,592
Single page for this topic Email Print Favorite

Quick Reply

You are signed in as our guest.

Looking for something else?
 

  LiveWire / Technical Forums / Programming & Application Development / Viewing Topic