使用C#窗口表单应用程序在用户登录期间节省登录时间
现在我正在尝试使用C#window form桌面应用程序获取用户日志。使用C#窗口表单应用程序在用户登录期间节省登录时间,c#,winforms,sqlclient,C#,Winforms,Sqlclient,现在我正在尝试使用C#window form桌面应用程序获取用户日志。 我试过了 我可以进入我的应用程序,没有数据保存到tbl_logusers 下一步该怎么做。请帮我解决这个问题。据我所知,您从未执行过命令。你需要 logcmd.ExecuteNonQuery(); 添加参数值之后 还可以使用来处理SqlConnection和SqlCommand而不是手动调用.Close()方法 不要再使用AddWithValue。使用或它的重载 using(SqlConnection con = new
我试过了 我可以进入我的应用程序,没有数据保存到tbl_logusers
下一步该怎么做。请帮我解决这个问题。据我所知,您从未执行过命令。你需要
logcmd.ExecuteNonQuery();
添加参数值之后
还可以使用来处理SqlConnection
和SqlCommand
而不是手动调用.Close()
方法
不要再使用AddWithValue
。使用或它的重载
using(SqlConnection con = new SqlConnection(conString))
using(SqlCommand cmd = con.CreateCommand())
{
// Set your CommandText propert of your query.
// Add your parameter values with SqlParameterCollection.Add() method
// Open your connection.
// Execute your query.
}
我强烈怀疑您试图将DateTime
值保存为time
列中的字符。不要那样做!将您的DateTime.Now
值(当然可能更可取)直接传递到您的DateTime
或相关类型的列
阅读:注意:使用本地机器时间不可靠,请使用服务器时间GETDATE(),而不是将datetimepicker的格式更改为(dd/mm/yy)格式,并放入SQL server的日期类型列中。但是,当我返回查询时,它会随时间出现,如何才能只获取日期。在DB中,它只显示日期。你能给我指个路吗。
using(SqlConnection con = new SqlConnection(conString))
using(SqlCommand cmd = con.CreateCommand())
{
// Set your CommandText propert of your query.
// Add your parameter values with SqlParameterCollection.Add() method
// Open your connection.
// Execute your query.
}