private void writeToDB(string password)///
        {

                string cmdstr = "INSERT INTO " + TableName + " (Password) values (@Password)" ;

                OleDbDataAdapter adapter = new OleDbDataAdapter();

                OleDbCommand insert = new OleDbCommand(cmdstr, vlAccessConnection);

                adapter.SelectCommand = insert;

                insert.Parameters.AddWithValue("@Password", password);
        }

Hi all this is the code i've insert to update data with
password = tbconfirmp.text; [under save();]

but it seems like there is an error insert.ExecuteNonQuery();
state
Syntax error in INSERT INTO statement.

I'm struck=(

Don't use a data adapter for this. Here is the code using Sql* data accessors but you can flip them over to OleDb*, they're more or less identical in calling:

public static string BuildSqlNativeConnStr(string server, string database)
    {
      return string.Format("Data Source={0};Initial Catalog={1};Integrated Security=True;", server, database);
    }
    private void simpleButton1_Click(object sender, EventArgs e)
    {
      const string query = "Insert Into Employees (RepNumber, HireDate) Values (@RepNumber, @HireDate)";
      string connStr = BuildSqlNativeConnStr("apex2006sql", "Leather");

      try
      {
        using (SqlConnection conn = new SqlConnection(connStr))
        {
          conn.Open();
          using (SqlCommand cmd = new SqlCommand(query, conn))
          {
            cmd.Parameters.Add(new SqlParameter("@RepNumber", 50));
            cmd.Parameters.Add(new SqlParameter("@HireDate", DateTime.Today));
            cmd.ExecuteNonQuery();
          }
        }
      }
      catch (SqlException)
      {
        System.Diagnostics.Debugger.Break();
      }
    }

Don't use a data adapter for this. Here is the code using Sql* data accessors but you can flip them over to OleDb*, they're more or less identical in calling:

public static string BuildSqlNativeConnStr(string server, string database)
    {
      return string.Format("Data Source={0};Initial Catalog={1};Integrated Security=True;", server, database);
    }
    private void simpleButton1_Click(object sender, EventArgs e)
    {
      const string query = "Insert Into Employees (RepNumber, HireDate) Values (@RepNumber, @HireDate)";
      string connStr = BuildSqlNativeConnStr("apex2006sql", "Leather");

      try
      {
        using (SqlConnection conn = new SqlConnection(connStr))
        {
          conn.Open();
          using (SqlCommand cmd = new SqlCommand(query, conn))
          {
            cmd.Parameters.Add(new SqlParameter("@RepNumber", 50));
            cmd.Parameters.Add(new SqlParameter("@HireDate", DateTime.Today));
            cmd.ExecuteNonQuery();
          }
        }
      }
      catch (SqlException)
      {
        System.Diagnostics.Debugger.Break();
      }
    }

meaning that i can change the sql to oledb and use?

Yes

Yes

but i'm also using

private const string TableName = "AdminPassword";///
        public const string DBFileName = "AdminPassword.mdb";///
        public OleDbConnection vlAccessConnection;///
        private string password;///
vlAccessConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DBFileName);///

            try///
            {
                vlAccessConnection.Open();
            }
            catch (OleDbException ee)
            {
                MessageBox.Show(ee.Message + ". StackTrace: " + ee.StackTrace.ToString());
            }///

i can see the code work the same way but how do they link back to data base file?=.

Yes

tried to edit to oledb even more error=/ and getting myself confuse=( but thank=)

Here is an example of inserting into an excel spreadsheet:

private static void WriteExcelFile()
    {
      string connStr = BuildExcel2007ConnectionString(@"C:\Data\Spreadsheet.xlsx", true);
      //Note 'rowNumber' is the first column in my spreadsheet.
      string query = @"Insert Into [Sheet1$] ([Row], [Name]) Values (?,?);";
      using (System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(connStr))
      {
        conn.Open();
        using (System.Data.OleDb.OleDbCommand cmd = new System.Data.OleDb.OleDbCommand(query, conn))
        {
          cmd.Parameters.Add(new System.Data.OleDb.OleDbParameter("Row", Convert.ToDouble(5)));
          cmd.Parameters.Add(new System.Data.OleDb.OleDbParameter("Name", "Fred"));
          cmd.ExecuteNonQuery();
        }
      }
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.