【发布时间】:2014-04-19 08:26:46
【问题描述】:
string constr = Properties.Settings.Default.Subject_1ConnectionString;
SqlConnection conn = new SqlConnection(constr);
SqlCommand com = new SqlCommand("SELECT * from Subject_Title WHERE Date BETWEEN @hello and @hello1 ", conn);
// com.Parameters.Add("@hello", SqlDbType.NVarChar).Value = textBox1.Text;
// com.Parameters.Add("@hello1", SqlDbType.NVarChar).Value = textBox2.Text;
com.Parameters.Add("@hello", SqlDbType.NVarChar);
com.Parameters["@hello"].Value = textBox1.Text;
com.Parameters.Add("@hello1", SqlDbType.NVarChar);
com.Parameters["@hello1"].Value = textBox2.Text;
// com.Parameters.AddWithValue("@hello", textBox1.Text);
// com.Parameters.AddWithValue("@hello1", textBox2.Text);
SqlDataAdapter da = new SqlDataAdapter(com);
DataSet ds = new DataSet();
da.Fill(ds, "Subject_title");
for (int i = 0; i < 8; i++)
{
this.labeltext = this.labeltext + " " + ds.Tables["Subject_Title"].Rows[i]["Date"].ToString();
this.labeltext = this.labeltext + " " + ds.Tables["Subject_Title"].Rows[i]["Subject"].ToString();
this.labeltext = this.labeltext + " ";
}
this.label1.Text = this.labeltext;
这里我没有从数据库中获取任何数据
Date 是我的列名,具有 nvarchar 类型,Subject 是另一个类型为 text 的列。
请大家解决我的问题
【问题讨论】:
-
你可以用单引号代替双引号,顺便说一句,你的日期类型是
datetime? -
不,我将其保留为 nvarchar
-
那你永远不会遇到该字段的问题,尽快将其更改为真正的日期时间字段
-
仍然没有获取任何数据
-
ntext、text和image数据类型将在 SQL Server 的未来版本中删除。避免在新的开发工作中使用这些数据类型,并计划修改当前使用它们的应用程序。请改用nvarchar(max)、varchar(max)和varbinary(max)。 See details here
标签: c# sql-server sql-server-2008 where between