Hi!
I need a big help in correcting my code. I am working with a sql database. Please anyone can convert this code to work with MsAccess Database please.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Globalization;
namespace LunaOffice
{
public partial class Facturacao : Form
{
frmRptFactuVenda facturavenda;
public Facturacao()
{
InitializeComponent();
}
SqlConnection conn;
SqlCommand comm;
string connstr = "Data Source=localhost\\sqlexpress;Initial Catalog=master;Integrated Security=True";
private void btnGravar_Facturacao_Click(object sender, EventArgs e)
{
{
conn = new SqlConnection(connstr);
comm = new SqlCommand();
conn.Open();
SqlParameter data = new SqlParameter("@datafact", SqlDbType.Date);
SqlParameter nomecliente = new SqlParameter("@nc", SqlDbType.NChar);
SqlParameter designacao = new SqlParameter("@desig", SqlDbType.NChar);
comm.Parameters.Add(data);
comm.Parameters.Add(nomecliente);
comm.Parameters.Add(designacao);
data.Value = DateTime.Today;
nomecliente.Value = nomeClienteFactu.Text;
designacao.Value = artigoFactu.Text;
comm.Connection = conn;
comm.CommandText = "insert into facturacao1 values(@datafact,@nc,@desig)";
comm.ExecuteNonQuery();
comm.CommandText = "select * from facturacao1;
SqlDataReader read = comm.ExecuteReader();
{
read.Close();
conn.Close();
}

Nitesh KejriwalRank #253 · 9.9K reputationPosted Sep 7, 2014, 7:32 PM EDT
1. SqlConnection to OledbConnection
2. SQLCommand to OledbCommand
3. SQLDataReader to OledbDataReader
4. SQLDbType to OledbDbType
5. SQLParameter to OledbParameter
and you should be good to run it against access.
Jignesh TrivediRank #16 · 50.3K reputationPosted Sep 7, 2014, 8:34 PM EDT
hi,
Please refer below link, it might help you.
http://msdn.microsoft.com/en-in/library/aa288452(v=vs.71).aspx
IsraelRank #1,223 · 1.5K reputationPosted Sep 8, 2014, 9:55 AM EDT
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.OleDb;
namespace LunaOffice
{
public partial class VisualRecursosHumanos : Form
{
OleDbConnection con = new OleDbConnection(@"Provider=SQLOLEDB; Data Source=c:\lunaoffice\lunaoffice\app_data\office.accdb;Persist Security Info=False;");
public VisualRecursosHumanos()
{
InitializeComponent();
}
OleDbConnection conn;
OleDbCommand comm;
string connstr = "Data Source=c:\\lunaoffice\\lunaoffice\\app_data\\office.accdb;Persist Security Info=False";
{
private void button71_Click(object sender, EventArgs e)
{
conn = new OleDbConnection(connstr);//Its makes a bugg here!!!
comm = new OleDbCommand();
conn.Open();
OleDbParameter nome = new OleDbParameter("@nome", OleDbType.Char);
comm.Parameters.Add(nome);
nome.Value = txtNomesCadasCandid.Text;
comm.Connection = conn;
comm.CommandText = "insert into funcionario values(@nome)";
comm.ExecuteNonQuery();
conn.Close();
}
IsraelRank #1,223 · 1.5K reputationPosted Sep 8, 2014, 3:22 PM EDT