使用sql数据适配器将空值插入sql表行

时间:2016-10-11 17:36:20

标签: c# sql-server null

SqlConnection connection = new SqlConnection(@"mycon_string"); 

SqlDataAdapter tabela_studenti_data = new SqlDataAdapter();

tabela_studenti_data.InsertCommand = new SqlCommand("Insert into tabela_studenti VALUES(@Fist_name,@Last_Name,@Notification_ID)",connection);

 tabela_studenti_data.InsertCommand.Parameters.Add("@First_name", SqlDbType.NVarChar, 50).Value = txtbox_emri.Text;

tabela_studenti_data.InsertCommand.Parameters.Add("@Last_name", SqlDbType.NVarChar, 50).Value = txtbox_mbiemri.Text;


**tabela_studenti_data.InsertCommand.Parameters.Add("@Notification_ID",SqlDbType.Int).Value = null;**

当我将最后一个代码与null相等时,代码不起作用。如果我等于一个随机数,它就可以了。我现在需要它null,但它似乎没有这样,任何想法?

1 个答案:

答案 0 :(得分:0)

    tabela_studenti_data.InsertCommand.Parameters.Add("@Notification_ID", SqlDbType.Int).Value=DBNull.Value;