C# .NET - Connecting to MSAccess database using C#
Asked By jason smith on 20-Jun-06 11:19 AM
I haven't used ADO.net so far.
I want to write some sample code to connect to MS Access database and insert some records.
can some one point me to some sample code ?
thanks
nath
OleDbCommand and OleDbConnection
Asked By F Cali on 20-Jun-06 11:29 AM
You can use the OleDbConnection and OleDbCommand objects to connect to an MS Access database and insert some records:
[CODE]
OleDbConnection oleDbConnection = new OleDbConnection(myConnectionString);
OleDbCommand oleDbCommand = new OleDbCommand();
oleDbCommand.Connection = oleDbConnection;
oleDbCommand.CommandText = "INSERT INTO YourTable ( Col1, Col2 ) VALUES (1, 'ABC')";
oleDbConnection.Open();
oleDbCommand.ExecuteNonQuery();
oleDbConnection.Close();
[/CODE]
thanks Ronald
Asked By jason smith on 20-Jun-06 12:13 PM
I want to take textboxes in textbox by using textbox1.Text property then insert in db / / } } public void InsertRecords(string id) { OleDbConnection conn = new OleDbConnection(@"Provider = Microsoft.Jet.OLEDB.4.0;Data Source = D: \ Esmail \ WebSite1 \ Allot.mdb"); string sql = "insert into Table2 select * from Table1, where ID in(" + id + ");"; conn.Open OleDbCommand cmd = new OleDbCommand(sql, conn); cmd.ExecuteNonQuery(); } } / / loop throgh all records and insert the value one by one call method for insert } } / / logic to insert in access data public void InsertRecords( string value) { OleDbConnection conn = new OleDbConnection(@ "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = D: \ Esmail \ WebSite1 \ Allot
want to connect the database acess to c#.net . . . please send example coding for that OledbConnection con = new OledbConnection( "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = C: \ mydatabase.mdb;" ); con.Open(); OledbCommand comm = new OledbCommand( "select * from Categories" , con); OledbDataAdapter da = new OledbDataAdapter(comm); DataTable dt = new DataTable(); da.Fill dt); con.Close(); dataGridView1.DataSource = dt; Hi, You can use the OleDbConnection and OleDbCommand objects to connect to an MS Access database and insert some records: OleDbConnection oleDbConnection = new OleDbConnection( " Provider = Microsoft.Jet.OLEDB.4.0; Data Source = C: \ db1.mdb" ); OleDbCommand
FROM [New Customers];" 14. 15. dbs. Close 16. 17. End Sub 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
add a column and save. . . C# .NET 06-Jun-13 10:03 AM Hello Friends OleDbConnection oleconn = new OleDbConnection (); oleconn.ConnectionString = @"Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " + constr; oleconn.Open(); OleDbCommand olecommand = new OleDbCommand (); olecommand.Connection = oleconn; olecommand.CommandText = "Select Id, Name, Name2 From Main" ; OleDbDataAdapter oleadap = new OleDbDataAdapter oleadap.SelectCommand = olecommand; OleDbCommand command2 = new OleDbCommand ( "UPDATE Main Set Name2 = ? " + "WHERE ID = ?" , oleconn); command2.Parameters.Add( "Name2" , OleDbType .VarChar, 120, "Name2 save this(Name3) column to DataBase. Please Help!! Try this code: public static OleDbDataAdapter CreateCustomerAdapter( OleDbConnection connection) { OleDbDataAdapter adapter = new OleDbDataAdapter(); OleDbCommand command; / / Create the SelectCommand. command = new OleDbCommand( "SELECT * FROM
string connectionString = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = D: \ maddy \ nifty \ niftydb.mdb;" ; OleDbConnection conn = new OleDbConnection (connectionString); conn.Open(); OleDbCommand cmd = new OleDbCommand (); cmd.Connection = conn; cmd.CommandText = "INSERT INTO nifty ([Title], [Publisher]) VALUES (@duser, @computer)" ; cmd.Parameters Page_Load ( object sender , EventArgs e ) { if (! IsPostBack ) { string sFilePath = Server . MapPath ( "MSACCESS.mdb" ); DataTable dt ; OleDbConnection Conn = new OleDbConnection (@ "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " + sFilePath + ";" ); using ( Conn ) { Conn . Open (); OleDbCommand cmd = new OleDbCommand ( "SELECT * FROM nifty" , Conn ); OleDbDataAdapter oDA = new OleDbDataAdapter ( cmd ); dt = new
i need code for calling a procedure in windows SQLCmd As New SqlCommand() 'The SQL Command SQLConn.ConnectionString = ConnString 'Set the Connection String SQLConn.Open 'Open the connection SQLCmd.Connection = SQLConn 'Sets the Connection to use with the SQL Command SQLCmd SQLdr As SqlDataReader 'The Local Data Store SQLConn.ConnectionString = ConnString 'Set the Connection String SQLConn.Open 'Open the connection SQLCmd.Connection = SQLConn 'Sets the Connection to use with the SQL Command SQLCmd language = "VB" runat = "server" > Sub Page_Load(Sender As Object, E As EventArgs) Dim objConnection As OleDbConnection Dim objCmd As OleDbCommand Dim strConnection As String strConnection = "Provider = Microsoft.Jet.OLEDB.4.0;" & _ "Data Source = C
I have Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string sFilePath = Server.MapPath( "MSACCESS.mdb" ); DataTable dt; OleDbConnection Conn = new OleDbConnection(@ "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " + sFilePath + ";" ); using (Conn) { Conn.Open(); OleDbCommand cmd = new OleDbCommand( "SELECT * FROM ARTICLE" , Conn); OleDbDataAdapter oDA = new OleDbDataAdapter(cmd); dt = new DataTable(); oDA.Fill(dt access-interaction-tutorial-part_t12054.html http: / / vb.net-informations.com / ado.net-dataproviders / ado.net-oledbconnection.htm Thank you for the info. I'll have a read see what problems I
string connectionString = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = D: \ maddy \ nifty \ niftydb.mdb;" ; OleDbConnection conn = new OleDbConnection (connectionString); conn.Open(); OleDbCommand cmd = new OleDbCommand (); cmd.Connection = conn; if (e.CommandName = = "upd" ) { LinkButton lkbupd = ( LinkButton )e.CommandSource as LinkButton ; GridViewRow string connectionString = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = D: \ maddy \ nifty \ niftydb.mdb;"; OleDbConnection conn = new OleDbConnection(connectionString); conn.Open(); OleDbCommand cmd = new OleDbCommand(); cmd.Connection = conn; if (e.CommandName = = "upd") { LinkButton lkbupd = (LinkButton)e
type mis matched in criteria expression what should i do ???? please give me suggestion try { OleDbConnection oc = new OleDbConnection(conString); oc.Open(); OleDbCommand db = new OleDbCommand("Select Purchased_Amount from PAYMENT where ID = '" + label4.Text + "'", oc); label56.Text = Convert.ToString(db.ExecuteScalar where clause as string. here is the correct code for you try { if (label4.Tex! = "" ) { OleDbConnection oc = new OleDbConnection(conString); oc.Open(); OleDbCommand db = new OleDbCommand( "Select Purchased_Amount from PAYMENT where ID = " + Convert.ToInt32(label4.Text) + "" , oc