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
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 231
1 OriginalGriff 223
2 nv3 50
3 VJ Reddy 45
4 Mehdi Gholam 45
0 Sergey Alexandrovich Kryukov 6,696
1 OriginalGriff 6,149
2 CPallini 2,473
3 Richard MacCutchan 1,697
4 Abhinav S 1,560


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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100