从数据库中获取空值 [英] Getting null value from database
本文介绍了从数据库中获取空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hello Guys,我正面临一个问题,即我从DB获取值null我在我的数据库中有值,但在我选择时我的表单中我得到null请帮助我怎么做
我尝试了什么:
Hello Guys, I am facing an issue that is I get value null from DB I have values in my DB but in my form when I select so I get null please help me how can I do it
What I have tried:
con_string.ConnectionString = @"Provider = Microsoft.ACE.OLEDB.12.0;Data Source =|DataDirectory|\Restaurant.accdb;Persist Security Info=False";
con_string.Open();
DataSet dsa22 = new DataSet();
DataTable dt22 = new DataTable();
dsa22.Tables.Add(dt22);
OleDbDataAdapter da22 = new OleDbDataAdapter();
string query = "SELECT count(column3) As [QTY] from [Total] Where [column3] like 'DineIn*' AND [Column1] <>0 AND Cancel IS NULL And [Date] Between #" + System.DateTime.Now.ToShortDateString() + "# AND #" + System.DateTime.Now.AddDays(1).ToShortDateString() + "# Group By [column3] ";
da22 = new OleDbDataAdapter(query,con_string);
da22.Fill(dt22);
con_string.Close();
int sum22 = 0;
for (int i = 0; i < dsa22.Tables[0].Rows.Count; ++i)
{
sum22 += Convert.ToInt32(dsa22.Tables[0].Rows[0][0].ToString());
}
Dinein_Orders.Text = sum22.ToString();
推荐答案
就在我的头顶;这样的事情可能会对你有所帮助。
Just off the top of my head; something like this might serve you better.
con_string.ConnectionString = @"Provider = Microsoft.ACE.OLEDB.12.0;Data Source =|DataDirectory|\Restaurant.accdb;Persist Security Info=False";
con_string.Open();
System.Data.IDbCommand cmd = con_string.CreateCommand() ;
cmd.CommandText = "SELECT count(column3) As [QTY] from [Total] Where [column3] like 'DineIn*' AND [Column1] <>0 AND Cancel IS NULL And [Date] Between ? AND ? Group By [column3] ";
System.Data.IDbDataParameter prm = cmd.CreateParameter() ;
prm.ParameterName = "?" ;
prm.Value = System.DateTime.Now;
cmd.Parameters.Add ( prm ) ;
prm = cmd.CreateParameter() ;
prm.ParameterName = "?" ;
prm.Value = System.DateTime.Now.AddDays(1) ;
cmd.Parameters.Add ( prm ) ;
Dinein_Orders.Text = cmd.ExecuteScalar().ToString();
con_string.Close();
我希望你'不要将日期存储为字符串。
I do hope you're not storing dates as strings.
这篇关于从数据库中获取空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文