Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在C中-仅获取日期的查询_C#_Sql_Sql Server - Fatal编程技术网

C# 在C中-仅获取日期的查询

C# 在C中-仅获取日期的查询,c#,sql,sql-server,C#,Sql,Sql Server,创建了具有“日期”列的表,使用了“日期时间”数据类型 如何用c更新查询编码只更新日期 是否有只显示日期的格式 我使用C代码 SqlCommand cmd = new SqlCommand(("Update tablename set Date = convert(GETDATE(),103) where Name ='" + TextBox1.Text + "' "), con); 按照这个模式, const string updateTable = "UPDATE [dbo].[Tablen

创建了具有“日期”列的表,使用了“日期时间”数据类型

如何用c更新查询编码只更新日期

是否有只显示日期的格式

我使用C代码

SqlCommand cmd = new SqlCommand(("Update tablename set Date = convert(GETDATE(),103) where Name ='" + TextBox1.Text + "' "), con);
按照这个模式,

const string updateTable = "UPDATE [dbo].[Tablename]
    SET [Date] = getutcdate()
    WHERE [Name] = @Name;"

using (var connection = new SqlConnection(youConnectionString))
{
    using(var command = new SqlCommand(updateTable, connection))
    {
        command.Parameters.AddWithValue("@Name", TextBox1.Text);
        connection.Open();
        command.ExecuteNonQuery();
    }
}

注入攻击,等等。为什么在数据库中以字符串形式存储日期?改为用户DateTime2。@GrantWinney我很抱歉被编辑了。谢谢你的回复comment@Jodrell注射攻击?这是C know so中的代码。@GrantWinney我没有提到C know so中的代码。@BAP最好的感谢是向上投票或接受。非常抱歉,我只有5个声誉,所以我不能vote@BAP工作吧,你的时间就到了。你能告诉我如何只显示日期而不显示日期吗time@BAP您必须从数据库中选择DateTime作为DateTime,然后使用类似于yourDateTime.toString的内容将值转换为字符串以进行表示。