SQL语句
SQL语句添加control
C#
1 //读取当天天气和风向 2 string sql = "select * from tb_QiXiang where NameID = 0001 and Date = '" + Convert.ToDateTime(Label3.Text.Trim()) + "'"; 3 SqlConnection con = new SqlConnection(ConString); 4 con.Open(); 5 SqlCommand cmd = new SqlCommand(sql, con); 6 SqlDataReader dr = cmd.ExecuteReader(); 7 while (dr.Read()) 8{ 9 Label6.Text = dr["Weather"].ToString(); 10 Label7.Text = dr["WDirec"].ToString(); 11} 12 con.Close();
ASP.NET
1 SelectCommand="SELECT * FROM [tb_QiXiang] WHERE (([Date] >= @Date) AND ([Date] < @Date2) AND ([NameID] = @NameID))"> 2 <SelectParameters> 3 <asp:ControlParameter ControlID="Label1" Name="Date" 4 PropertyName="Text" Type="DateTime" /> 5 <asp:ControlParameter ControlID="Label2" Name="Date2" 6 PropertyName="Text" Type="DateTime" /> 7 <asp:Parameter DefaultValue="0001" Name="NameID" Type="String" /> 8 </SelectParameters>