Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Access
I am creating a connection string using ms access and saving the record in ms access data base.
 
My code is as follows in global function(Class file);
      private string Accessconncetionstring ="Provider= microsoft.jet.OLEDB.4.0;Data Source=Data\\HIMTTESTing.mdb";
 
      public void BindAccessConn()
      {
            con = new SqlConnection();
            con.ConnectionString = Accessconncetionstring;
            con.Open();
      }
 
      public void InsertAccessData(string SQL)
      {
            try
            {
                BindAccessConn();
                cmd = new SqlCommand(SQL, con);
                cmd.ExecuteReader();
            }
            catch (Exception e1)
            {
                Error = e1.Message.ToString();
            }
      }
 
      public SqlDataReader ReadAcessSql(string SQL)
      {
 
            con = new SqlConnection(Accessconncetionstring);
            con.Open();
            cmd = new SqlCommand(SQL, con);
            dr = cmd.ExecuteReader();
            return (dr);
      }
 
      public string CntAcessString()
      {
           return Accessconncetionstring;
      }
 
      //Save record code as follows;

      private GlobalFunction GFun = new GlobalFunction();
      private string sql;
 

      private void BtnSaves_Click(object sender, EventArgs e)
      {
            SaveDetails();
      }
 
      private void SaveDetails()
      {
            //save coding starts
            try
            {
                string sql;
                for (int i = 0; i < datagridView.RowCount; i++)
                {
                    for (int j = 2; j < datagridView.ColumnCount; j++)
                    {
                          if(datagridView[j, i].Value != DBNull.Value && datagridView[j, i].Value !=  "" && datagridView[j, i].Value != null )
 
                        {
                            sql = "insert into Tb_SCh_TIme_Table(Date,Session,Course,Faculty_Code)" + " values ('" + Convert.ToDateTime(datagridView.Rows[i].Cells[0].Value.ToString()) + "', '" + int.Parse(datagridView.Rows[i].Cells[1].Value.ToString()) + "', '" + datagridView[j, i].Value.ToString() + "','" + datagridView.Columns[j].HeaderText.ToString() + "')";
                            try
                            {
                                GFun.Error = "";
                                GFun.InsertAccessData(sql);
                                if (GFun.Error.ToString() != "")
                                {
                                    MessageBox.Show(GFun.Error.ToString(), "Error");
                                    return;
                                }
                            }
 
                            catch (Exception Ex)
                            {
                                MessageBox.Show(Ex.ToString(), "Error");
                            }
                        }
                    }
                }
            }
            catch (Exception Ex1)
            {
                MessageBox.Show(Ex1.ToString(), "Error", MessageBoxButtons.OK);
            }
      }
In run time, all records are entered and the save button is clicked.
Error shows as follows;
 
KEYWORD NOT SUPPORTED 'PROVIDER';
 
I THINK IN THE BELOW LINE IS PROBLEM AS FOLLOWS.
 
private string Accessconncetionstring ="Provider= microsoft.jet.OLEDB.4.0;Data Source=Data\\HIMTTESTing.mdb";

 
HIMTTESTing is ms access data base name. In that database tables are there.
 
From my above code, what is the the mistake? How can i do? Help me.
Posted 23-Jan-13 2:28am
Edited 23-Jan-13 2:59am
Tadit Dash85.6K
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

The documentation for System.Data.SqlClient.SQLConnection says it is to be used for connecting to SQL Server.
 
I think you should use System.Data.OleDb.OleDbConnection instead of System.Data.SqlClient.SQLConnection.
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 756
1 OriginalGriff 452
2 Tadit Dash 350
3 sanket saxena 329
4 Peter Leow 228
0 Sergey Alexandrovich Kryukov 11,890
1 OriginalGriff 7,335
2 Peter Leow 5,003
3 Abhinav S 3,943
4 Maciej Los 3,575


Advertise | Privacy | Mobile
Web01 | 2.8.140421.2 | Last Updated 23 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid