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
Marvin kakuru
1.4k
359
160.8k
Access database
Mar 2 2012 6:13 AM
Hi everyone,
I hope your all alright. I have been running my c sharp program using an sql server database, unfortunately it has expired so I am trying to migrate to an access data base. Below is some code I used to run using mysql and now using Microsoft access database it is not working.
if (textBox2.Text == "")
{
OleDbConnection cn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\katoto\Documents\Visual Studio 2010\Projects\Genesis Philcollins\data\thyfarm.accdb;Jet OLEDB:Database Password=Kyozi");
string sql = ("select expensecodeid,expensecode,narration,cost,dateofnextp from expenseac where dateofnextp = '" + DateTime.Now.ToString("dd/MM/yyyy") + "'OR dateofnextp = '" + DateTime.Now.AddDays(1).ToString("dd/MM/yyyy") + "'OR dateofnextp = '" + DateTime.Now.AddDays(2).ToString("dd/MM/yyyy") + "'OR dateofnextp = '" + DateTime.Now.AddDays(3).ToString("dd/MM/yyyy") + "'OR dateofnextp = '" + DateTime.Now.AddDays(4).ToString("dd/MM/yyyy") + "' AND yr LIKE '" + label5.Text + "'ORDER BY dateofnextp");
DataSet ds;
OleDbCommand cmd = new OleDbCommand();
OleDbDataAdapter da = new OleDbDataAdapter();
cmd = new OleDbCommand(sql, cn);
da = new OleDbDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds, "select expensecodeid,expensecode,narration,cost,dateofnextp");
dataGridView1.DataSource = ds.Tables[0];
{
dataGridView1.Columns["expensecodeid"].Width = 100;
dataGridView1.Columns["expensecode"].Width = 120;
dataGridView1.Columns["narration"].Width = 150;
dataGridView1.Columns["cost"].Width = 100;
dataGridView1.Columns["dateofnextp"].Width = 100;
}
}
I used this code to select data with a date one,two,three,four and even five days from to days date. I have set the column "dateofnextp" in my access database to date/time – shortdate which is dd/MM/yyyy
When I run my program I am getting an error "OleDbException was unhandled - Data type mismatch in criteria expression."
Any help will be greatly appreciated.
Best Regards.Marvin
Reply
Answers (
1
)
Finalize part: bug check
USB Connection