TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
james james
NA
419
30k
c# Refresh Access Database
Oct 31 2017 4:26 PM
I am able to Save Data to a Access databse , now when i add new entry i try to refresh the database but the new entry dont show until i close the program and open it back up. I have 2 buttons one Update and the other Refresh. I am using Parameters. It would be better to use one meathod to do both (thats over my head at the moment) so i have 2 buttons. I dont get any errors when i try to Refresh so I dont know where to start.
Thanks
My Update code working fine.
private
void
btnUpdate_Clicked(
object
sender, RoutedEventArgs e)
{
using
(var myCon =
new
OleDbConnection(ConfigurationManager.ConnectionStrings[
"Connection"
].ToString()))
{
using
(var myCmd =
new
OleDbCommand(
"insert into [Sheet1](Box1,Box2,Box3,Box4,Box5,Box6,Box7,Box8)Values(@nm1,@nm2,@nm3,@nm4,@nm5,@nm6,@nm7,@nm8)"
, myCon))
{
myCmd.Parameters.AddWithValue(
"@nm1"
, txt_Box1);
myCmd.Parameters.AddWithValue(
"@nm2"
, txt_Box2);
myCmd.Parameters.AddWithValue(
"@nm3"
, txt_Box3.Text);
myCmd.Parameters.AddWithValue(
"@nm4"
, txt_Box4.Text);
myCmd.Parameters.AddWithValue(
"@nm5"
, TXT_Box5.Text);
myCmd.Parameters.AddWithValue(
"@nm6"
, txt_Box6.Text);
myCmd.Parameters.AddWithValue(
"@nm7"
, txt_Box7.Text);
myCmd.Parameters.AddWithValue(
"@nm8"
, txt_Box8.Text);
try
{
myCon.Open();
int
z = myCmd.ExecuteNonQuery();
if
(z > 0)
{
MessageBox.Show(
"Data Inserted"
);
}
}
catch
(Exception ex)
{
//Handle exception as needed
}
}
}
}
My Refresh is not refreshing the data base no errors givens.
private
void
btn_Refresh_Click(
object
sender, EventArgs e)
{
using
(var myCon =
new
OleDbConnection(ConfigurationManager.ConnectionStrings[
"Connection"
].ToString()))
{
using
(var myCmd =
new
OleDbCommand(
"UPDATE Sheet1 SET Box1 =@nm1,Box2 = @nm2, Box3=@nm3, Box4 = @nm4, Box5 = @nm5,Box6 = @nm6, Box7 = @nm7 WHERE Box8 = @nm8"
, myCon))
{
myCmd.Parameters.AddWithValue(
"@nm1"
, txt_Box1.Text);
myCmd.Parameters.AddWithValue(
"@nm2"
, txt_Box2.Text);
myCmd.Parameters.AddWithValue(
"@nm3"
, txt_Box3.Text);
myCmd.Parameters.AddWithValue(
"@nm4"
, txt_Box4.Text);
myCmd.Parameters.AddWithValue(
"@nm5"
, TXT_Box5.Text);
myCmd.Parameters.AddWithValue(
"@nm6"
, txt_Box6.Text);
myCmd.Parameters.AddWithValue(
"@nm7"
, txt_Box7.Text);
myCmd.Parameters.AddWithValue(
"@nm8"
, txt_Box8.Text);
try
{
myCon.Open();
int
z = myCmd.ExecuteNonQuery();
MessageBox.Show(
"Data Updated"
);
}
catch
(Exception ex)
{
//Handle exception as needed
}
}
}
}
Reply
Answers (
2
)
Petrol Pump Filling station
Change Dektop Background Color