Click here to Skip to main content
15,887,596 members
Home / Discussions / Database
   

Database

 
QuestionHow to Insert a comma "," in the SQL SERVER? Pin
Anonymous26-May-04 12:00
Anonymous26-May-04 12:00 
AnswerRe: How to Insert a comma "," in the SQL SERVER? Pin
Om Prakash Pant5-Jun-04 1:11
Om Prakash Pant5-Jun-04 1:11 
GeneralRe: How to Insert a comma "," in the SQL SERVER? Pin
afronaut14-Jul-04 14:46
afronaut14-Jul-04 14:46 
QuestionHow to Insert a comma "," in the SQL SERVER? Pin
Anonymous26-May-04 11:59
Anonymous26-May-04 11:59 
AnswerRe: How to Insert a comma "," in the SQL SERVER? Pin
Garth J Lancaster26-May-04 12:56
professionalGarth J Lancaster26-May-04 12:56 
AnswerRe: How to Insert a comma "," in the SQL SERVER? Pin
Edbert P26-May-04 12:57
Edbert P26-May-04 12:57 
Generalstoring data into access Pin
DustinWehler26-May-04 8:18
DustinWehler26-May-04 8:18 
GeneralRe: storing data into access Pin
Mike Ellison26-May-04 10:45
Mike Ellison26-May-04 10:45 
Hi there, Dustin. I would recommend you look at some tutorials to get you started with ASP.NET and database handling. The QuickStart tutorials[^] are a good place to start. In particular, you'll want to read the tutorial "Server-Side Data Access" from the QuickStarts.

You'll start to familiarize yourself with the data objects that you'll need. In a nutshell, you'll find them in the System.Data and System.Data.OleDb namespaces (look for these in the .NET SDK documentation.) You'll use an OleDbConnection object to establish a connection to your access .mdb file. You'll then create an OleDbCommand object to represent your insert statement. Use OleDbParameter objects with the OleDbCommand to apply the values from your textboxes, and use the ExecuteNonQuery method to issue the command to the database. When selecting records you'll likely use a DataSet object or perhaps an OleDataReader

Here is a very raw example of a page that performs an insert to an Access database (in C#):
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Page Language="C#" %>

<script runat="server">
  void btnSubmit_Click(object o, EventArgs e)
  {
    // provide a connection string to the database
    const string kCONNECT_STRING = 
      "Provider=Microsoft.Jet.OLEDB.4.0; "
      + @"Data Source=c:\inetpub\wwwroot\tests\test.mdb";
    
    // provide the insert statement, with @parameters
    const string kINSERT_STATEMENT = 
      "INSERT INTO [MyTable] ([E-Name], [E-Email]) " 
      + " Values (@pName , @pEmail) ";
    
    OleDbConnection con = null;
    OleDbCommand cmd = null;  
    OleDbParameter pName = null; 
    OleDbParameter pEmail = null; 
    int insertedID = -1;
    
    try
    {
      // get the connection
      con = new OleDbConnection(kCONNECT_STRING);
      con.Open();
      
      // create the insert command
      cmd = new OleDbCommand(kINSERT_STATEMENT, con);
      
      // add parameter values
      pName = new OleDbParameter("@pName", DbType.String);
      pName.Value = tbName.Text;
      cmd.Parameters.Add(pName);
      
      pEmail = new OleDbParameter("@pEmail", DbType.String);
      pEmail.Value = tbEmail.Text;
      cmd.Parameters.Add(pEmail);
      
      // execute the insert command
      cmd.ExecuteNonQuery();
      
      // retrieve the autonumber that was just inserted
      cmd.CommandText = "SELECT @@Identity";
      cmd.CommandType = CommandType.Text;
      cmd.Parameters.Clear();
      insertedID = (int)cmd.ExecuteScalar();

      
      // if we're still here there's been no exceptions;
      // display a message
      Response.Write(
        string.Format("Record has been inserted and assigned ID# {0}."
                      ,insertedID) );
      
    }
    catch (Exception x)
    {
      // on an error, display a message
      Response.Write("There has been an error.  ");
      Response.Write(x.Message);
    }
    finally
    {
      // dispose objects
      if (cmd != null) cmd.Dispose();
      if (con != null) con.Dispose();      
    }
      
  }    
</script>

<html>
  <head>
  </head>
  
  <body>
    <form runat="server">
      <h3>Insert into Access</h3>
      <table>
        <tr>
            <td>Name</td>
            <td><asp:TextBox id="tbName" runat="server" /></td>
        </tr>
        <tr>
            <td>Email</td>
            <td><asp:TextBox id="tbEmail" runat="server" /></td>
        </tr>
      </table>
      <asp:Button id="btnSubmit" runat="server" text="Insert"
                  onClick="btnSubmit_Click" />
    </form>
  </body>
  
</html>
Another way to go about it is to use the OleDbDataAdapter object - there happens to be a good article on MSDN[^] that discusses how to retrieve the autonumber value after an insert, and their sample code uses OleDbDataAdapter. You may want to go in that direction.

One final word: Access is a good single-user desktop database. It is not as good as other RDBMS (for a variety of reasons) when it comes to multi-user web applications. SQL Server or Oracle may be better choices if you have the $$$. If cost is an issue, you may want to investigate using MSDE - a lighter-weight SQL Server from Microsoft, or perhaps even MySQL.

I hope this helps.
GeneralRe: storing data into access Pin
afronaut14-Jul-04 14:42
afronaut14-Jul-04 14:42 
GeneralACCESS 2000 &amp; SQL Pin
Bob Stanneveld26-May-04 5:30
Bob Stanneveld26-May-04 5:30 
GeneralRe: ACCESS 2000 & SQL Pin
Michael Potter26-May-04 6:51
Michael Potter26-May-04 6:51 
GeneralRe: ACCESS 2000 & SQL Pin
Bob Stanneveld26-May-04 6:57
Bob Stanneveld26-May-04 6:57 
GeneralRe: ACCESS 2000 &amp; SQL Pin
Michael Potter26-May-04 8:19
Michael Potter26-May-04 8:19 
GeneralRe: ACCESS 2000 &amp; SQL Pin
Bob Stanneveld26-May-04 8:29
Bob Stanneveld26-May-04 8:29 
GeneralRe: ACCESS 2000 &amp; SQL Pin
Serge Lobko-Lobanovsky1-Jun-04 0:41
Serge Lobko-Lobanovsky1-Jun-04 0:41 
GeneralRe: ACCESS 2000 &amp; SQL Pin
Bob Stanneveld1-Jun-04 6:02
Bob Stanneveld1-Jun-04 6:02 
General@@trancount problem Pin
williamchou25-May-04 21:01
williamchou25-May-04 21:01 
GeneralRe: @@trancount problem Pin
Venkatraman25-May-04 22:04
Venkatraman25-May-04 22:04 
GeneralRe: @@trancount problem Pin
williamchou25-May-04 22:10
williamchou25-May-04 22:10 
GeneralRe: @@trancount problem Pin
Hesham Amin25-May-04 23:51
Hesham Amin25-May-04 23:51 
GeneralRe: @@trancount problem Pin
williamchou26-May-04 0:03
williamchou26-May-04 0:03 
GeneralRe: @@trancount problem Pin
williamchou26-May-04 0:08
williamchou26-May-04 0:08 
GeneralRe: @@trancount problem Pin
Hesham Amin26-May-04 0:10
Hesham Amin26-May-04 0:10 
GeneralRe: @@trancount problem Pin
williamchou26-May-04 0:24
williamchou26-May-04 0:24 
GeneralRe: @@trancount problem Pin
williamchou26-May-04 15:54
williamchou26-May-04 15:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.