Fisnik Maloku Fisnik Maloku - 1 month ago 14
C# Question

Insert null value into sql table row using sql data adapter

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;**


When I equal the last code with null , the code doesn't work , if I equal with a random number it works, I need it null for now ? but It doesn't seem to go this way . any Ideas ?

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