本文介绍了C#如何根据时间访问从数据库中获取值并将其显示在文本框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在google上找到的这段代码.
我试图从数据库中获取值并将其显示在文本框中.基于时间
I am trying this code i found on google.
and i''m trying to fetch value from database and display it on a textbox. based it on a time
OleDbConnection cn = new OleDbConnection();
cn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\`Hp\Desktop\PROGRAM1\notificationSystem\notificationSystem\Database.accdb";
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = cn;
string cmdText = "SELECT * FROM news " +
"WHERE npublished BETWEEN ? AND ?";
DateTime dt = this.metroDateTime1.Value.Date;
DateTime dt2 = this.metroDateTime1.Value.Date.AddMinutes(1440);
cmd.CommandText = cmdText;
cmd.Parameters.AddWithValue("@p1", dt);
cmd.Parameters.AddWithValue("@p2", dt2);
cmd.Parameters.AddWithValue("@article", metroTextBox2.Text);
OleDbDataAdapter adapter = new OleDbDataAdapter(cmdText, cn);
DataSet ds = new DataSet();
adapter.Fill(ds);
Form5 f5 = new Form5();
f5.newsGrid.DataSource = ds.Tables[0];
cn.Close();
我应该怎么办?我想念什么吗?
任何帮助将不胜感激.
我尝试过的事情:
尝试了上面的代码,但无法正常工作.
What should i do? do i miss something?
Any help would be gladly appreciated.
What I have tried:
Tried the code above but it won''t work.
推荐答案
这篇关于C#如何根据时间访问从数据库中获取值并将其显示在文本框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!