C# .NET - insert statement for msaccess? - Asked By avula on 09-Jan-12 04:38 AM

hi

insert statement for msaccess?

please help me
kalpana aparnathi replied to avula on 09-Jan-12 04:41 AM
hi,

01.Sub InsertIntoX1()
02. 
03.  Dim dbs As Database
04. 
05.  ' Modify this line to include the path to Northwind
06.  ' on your computer.
07.  Set dbs = OpenDatabase("Northwind.mdb")
08.   
09.  ' Select all records in the New Customers table
10.  ' and add them to the Customers table.
11.  dbs.Execute " INSERT INTO Customers " _
12.    & "SELECT * " _
13.    & "FROM [New Customers];"
14.     
15.  dbs.Close
16. 
17.End Sub
smr replied to avula on 09-Jan-12 04:42 AM
hi

try this code

OleDbConnection oleDbConnection = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0; Data Source=" + Server.MapPath("~/app_data/users.mdb"));
OleDbCommand oleDbCommand = new OleDbCommand();
oleDbCommand.Connection = oleDbConnection;
oleDbCommand.CommandText = "insert into tablename(Username, Password)VALUES ('" + TextBox1.Text + "', '" + TextBox2.Text + "')";
oleDbConnection.Open();
oleDbCommand.ExecuteNonQuery();
oleDbConnection.Close();
kalpana aparnathi replied to avula on 09-Jan-12 04:42 AM
Syntax

Multiple-record append query:

INSERT INTO target [(field1[, field2[, ...]])] [IN externaldatabase]
SELECT [source.]field1[, field2[, ...]
FROM tableexpression

Single-record append query:

INSERT INTO target [(field1[, field2[, ...]])]
VALUES (value1[, value2[, ...])

The INSERT INTO statement has these parts:

Part Description
target The name of the table or query to append records to.
field1, field2 Names of the fields to append data to, if following a target argument, or the names of fields to obtain data from, if following a source argument.
externaldatabase The path to an http://office.microsoft.com/en-us/access-help/redir/HP001044193.aspx?CTT=5&origin=HP001032245 . For a description of the path, see the IN clause.
source The name of the table or query to copy records from.
tableexpression The name of the table or tables from which records are inserted. This argument can be a single table name or a compound resulting from an INNER JOIN , LEFT JOIN , or RIGHT JOIN operation or a saved query.
value1, value2 The values to insert into the specific fields of the new record. Each value is inserted into the field that corresponds to the value's position in the list: value1 is inserted into field1 of the new record, value2 into field2, and so on. You must separate values with a comma, and enclose text fields in quotation marks (' ').
dipa ahuja replied to avula on 09-Jan-12 06:12 AM
using System.Data.OleDb;
 

  using (OleDbConnection conn = new OleDbConnection(connect))
  {
    using (OleDbCommand cmd = new OleDbCommand())
    {
      cmd.Connection = conn;
      cmd.CommandText = "INSERT INTO table1 values('" + textbox1.Text + "')";
      conn.Open();
      cmd.ExecuteNonQuery();
    }
  }
}