954,525 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Add record to access database

I'm using an access database to save plain textboxes.
I've made a connection with the database. Now i need to find the code to add the textboxes to my database.

I've tried to add with the bindingnavigator but it won't work...

please help...

Isaaac
Newbie Poster
20 posts since Apr 2010
Reputation Points: 9
Solved Threads: 0
 

I'm using an access database to save plain textboxes. I've made a connection with the database. Now i need to find the code to add the textboxes to my database.

I've tried to add with the bindingnavigator but it won't work...

please help...

Use System.Data.OleDb connection, command, and parameter classes.

OleDbConnection cn=new OleDbConnection(@"put_connection_string_here");
OleDbCommand cmd=new OleDbCommand("insert into tableName (col1,col2) values (@para1,@para2)",cn);

cmd.Parameters.AddWithValue("@para1",TextBox1.Text);
cmd.Parameters.AddWithValue("@para2",TextBox2.Text);

cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

I've found the way using the bindingnavigator, but there's one problem, i use 2 forms, one to add the database and one to display items. So i need to restart my program everytime I added something before i can see it in my main form. How can i refresh my database of my mainform?

Isaaac
Newbie Poster
20 posts since Apr 2010
Reputation Points: 9
Solved Threads: 0
 
I've found the way using the bindingnavigator, but there's one problem, i use 2 forms, one to add the database and one to display items. So i need to restart my program everytime I added something before i can see it in my main form. How can i refresh my database of my mainform?


Presume that the Form2 has data entry UI.

In the click handler of button,

Form2 frm=new Form2();
  frm.ShowDialog();

  //Write here code to fetch & rebind the datasource.
__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

Presume that the Form2 has data entry UI.

In the click handler of button,

Form2 frm=new Form2();
  frm.ShowDialog();

  //Write here code to fetch & rebind the datasource.

Form2 has data entry UI?
Sorry ( noob ), does every form have this or do you have to add it?

Isaaac
Newbie Poster
20 posts since Apr 2010
Reputation Points: 9
Solved Threads: 0
 
Form2 has data entry UI? Sorry ( noob ), does every form have this or do you have to add it?


one to add the database.

__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 
one to add the database.

Yeah, i've done that.
I open a second form and mainform is still displayed in background, do i have to close and reopen the mainform?

Isaaac
Newbie Poster
20 posts since Apr 2010
Reputation Points: 9
Solved Threads: 0
 

Please post your code here.

__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

Here's my whole project, you probably can't build it because it involves handshaking with PIC16F877..

Isaaac
Newbie Poster
20 posts since Apr 2010
Reputation Points: 9
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: