2016-10-11 9 views
0
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が必要ですが、それはこのように、任意のアイデアを行くようには見えないのですか?SQLデータアダプタを使用してSQLテーブル行にNULL値を挿入します。

+0

あなたのテーブル構造は何ですか?なぜ、INSERT文に列を指定しなかったのですか?列名を指定せずに挿入することは、常に悪い考えです。 – HLGEM

+3

[DBNull]を試してください(https://msdn.microsoft.com/en-us/library/system.dbnull(v = vs.110).aspx) –

+1

まだ 'DBNull'を試しましたか? –

答えて

0
tabela_studenti_data.InsertCommand.Parameters.Add("@Notification_ID", SqlDbType.Int).Value=DBNull.Value; 
関連する問題