locked
Insert Data to Access DB in ASP.net RRS feed

  • Question

  • User-48338350 posted

    Hi all,


    I am a new with ASP.net.

    Plase help me about ASP.net code for connect to Access database for insert, update and delete data.


    thanks

    Tuesday, November 16, 2010 2:37 AM

Answers

  • User-821857111 posted

    None of your code looks anything remotely like the samples in my articles, so you obviously didn't read them. However:

    Dim ConnectionString As String = .....

    The connection connects to your database and the DataSet is a container for the data your retrieve when you use a SELECT statement.


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 17, 2010 12:43 AM

All replies

  • User-48338350 posted

    Hi.

    I still complicate about the connection and using the dataset. How they related eachother?

    Would u please conbind it in a page?


    I try with this code but it not working.

        Dim con As New System.Data.OleDb.OleDbConnection
        Dim myPath As String
        myPath = Server.MapPath("NetLibrary_files/DB/CamNetLib.mdb")
        ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data source=" & myPath & ";"
                
        OleDbConnection con = new OleDbConnection(ConnectionString);
        con.Open();
     
        OleDbCommand cmd = new OleDbCommand();
        cmd.Connection = con;
        
        cmd.CommandText = "INSERT INTO tblMember ([Username], [Mail], [PWD],[Sex]) VALUES (@Username, @Mail, @PWD,@Sex)";
        cmd.Parameters.Add("@Username", OleDbType.VarChar).Value = "Nanana";
        cmd.Parameters.Add("@Mail", OleDbType.VarChar).Value = "nana@gmail.com";
        cmd.Parameters.Add("@PWD", OleDbType.VarChar).Value = "123456";
        cmd.Parameters.Add("@Sex", OleDbType.VarChar).Value = "Male";
      
        
        cmd.ExecuteNonQuery();
        conn.Close();



    Compilation Error

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: BC30451: Name 'ConnectionString' is not declared.

    Source Error:


    Line 212:    Dim myPath As String
    Line 213: myPath = Server.MapPath("NetLibrary_files/DB/CamNetLib.mdb")
    Line 214: ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data source=" & myPath & ";"
    Line 215:
    Line 216: OleDbConnection con = new OleDbConnection(ConnectionString);


    Thanks,


    Tuesday, November 16, 2010 8:31 PM
  • User-821857111 posted

    None of your code looks anything remotely like the samples in my articles, so you obviously didn't read them. However:

    Dim ConnectionString As String = .....

    The connection connects to your database and the DataSet is a container for the data your retrieve when you use a SELECT statement.


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 17, 2010 12:43 AM