我有一个表格,我添加Datetime到一些列.我使用存储过程将值插入表中.在存储过程中,我有变量接受null以插入表中.我的问题是当我尝试在我的表列中插入一个空值时,我在列中得到1900-01-01.我该怎么办而不是这个默认值在colulmn中只插入NULL?
这是我的SP:
CREATE PROCEDURE dbo.Insert
@InserID int,
@InsertDate Datetime = null,
AS
Insert into Tables(InsertID, InsertDate)
Values(@InsertID, @InsertDate)
Run Code Online (Sandbox Code Playgroud)
我这样做是为了分配一个空值:
System.Data.SqlTypes.SqlDateTime getDate;
//set DateTime null
getDate = SqlDateTime.Null;
if (InsertDate.Text == "")
{
cmd1.Parameters["@InsertDate"].Value = getDate;
}
else
{
cmd1.Parameters["@InsertDate"].Value = InsertDate.Text;
}
Run Code Online (Sandbox Code Playgroud)
添加到我的表列的值不是NULL,它是1900-01-01.
我该怎么办?
我在winform应用程序中有4个从我的数据库中获取值的数据集.价值就像我的产品表中有多少产品和类别信息.我想知道如何在html页面中保存数据集信息.我想创建一个html模板,以便我能以很好的方式呈现信息.我怎样才能做到这一点?Eny好的指南解释了如何做到这一点?
我试图像这样将一些值插入到SQL CE数据库中,但没有任何反应。我做错了什么?
string strConn = Properties.Settings.Default.SqlConnectionString;
using (SqlCeConnection con = new SqlCeConnection(strConn))
{
con.Open();
using (SqlCeCommand cmd = new SqlCeCommand("insert into CustTable(ID, Name) values (@Val1, @val2)", con))
{
cmd.Parameters.AddWithValue("@Val1", customer.ID);
cmd.Parameters.AddWithValue("@Val2", customer.Name);
cmd.CommandType = System.Data.CommandType.Text;
cmd.ExecuteNonQuery();
}
}
Run Code Online (Sandbox Code Playgroud)