Abdalla Elawad

Abdalla Elawad

  • NA
  • 1k
  • 215.2k

Insert Code C# Save Null Value What is Problem ?

Aug 28 2016 6:08 AM

Hi guys:

I have Problem in Save Code explain as below also attached Table

I do not need Save Null Value ?

Code must doesn’t Save Null Value . Please Help Me

protected void Button1_Click(object sender, EventArgs e)

{

try

{

SqlCommand cmd = new SqlCommand("InBound_Insert", Conn);

cmd.Parameters.Add("@FleetNo", SqlDbType.VarChar).Value = TextBox1.Text.Trim();

cmd.Parameters.Add("@RegisterNo", SqlDbType.VarChar).Value = TextBox2.Text.Trim();

cmd.Parameters.Add("@RegisterAlpha", SqlDbType.VarChar).Value = TextBox3.Text.Trim();

cmd.Parameters.Add("@VehcileKey", SqlDbType.VarChar).Value = TextBox4.Text.Trim();

cmd.Parameters.Add("@Weapon", SqlDbType.VarChar).Value = TextBox5.Text.Trim();

cmd.Parameters.Add("@WeaponBullets", SqlDbType.VarChar).Value = TextBox6.Text.Trim();

cmd.Parameters.Add("@HandheldTerm", SqlDbType.VarChar).Value = TextBox7.Text.Trim();

cmd.Parameters.Add("@CustomerKey", SqlDbType.VarChar).Value = TextBox8.Text.Trim();

cmd.Parameters.Add("@Mileage", SqlDbType.VarChar).Value = TextBox9.Text.Trim();

cmd.Parameters.Add("@EmpDriver", SqlDbType.NVarChar).Value = (DropDownList1.SelectedValue);

cmd.Parameters.Add("@EmpCustd1", SqlDbType.NVarChar).Value = (DropDownList2.SelectedValue);

cmd.Parameters.Add("@EmpCustd2", SqlDbType.NVarChar).Value = (DropDownList3.SelectedValue);

cmd.Parameters.Add("@ID_Driver", SqlDbType.NVarChar).Value = (DropDownList4.SelectedValue);

cmd.Parameters.Add("@ID_Cusdt1", SqlDbType.NVarChar).Value = (DropDownList5.SelectedValue);

cmd.Parameters.Add("@ID_Cusdt2", SqlDbType.NVarChar).Value = (DropDownList6.SelectedValue);

cmd.Parameters.Add("@PostionDriver", SqlDbType.NVarChar).Value = (DropDownList7.SelectedValue);

cmd.Parameters.Add("@PositionCusd1", SqlDbType.NVarChar).Value = (DropDownList8.SelectedValue);

cmd.Parameters.Add("@PositionCusd2", SqlDbType.NVarChar).Value = (DropDownList9.SelectedValue);

cmd.Parameters.Add("@MobileDriver", SqlDbType.NVarChar).Value = (DropDownList10.SelectedValue);

cmd.Parameters.Add("@MobileCustd1", SqlDbType.NVarChar).Value = (DropDownList11.SelectedValue);

cmd.Parameters.Add("@MobileCustd2", SqlDbType.NVarChar).Value = (DropDownList12.SelectedValue);

cmd.Parameters.Add("@Customer", SqlDbType.NVarChar).Value = (DropDownList13.SelectedValue);

cmd.Parameters.Add("@ServiceType", SqlDbType.NVarChar).Value = (DropDownList14.SelectedValue);

cmd.Parameters.Add("@TripTeam", SqlDbType.NVarChar).Value = (DropDownList15.SelectedValue);

cmd.CommandType = CommandType.StoredProcedure;

Conn.Open();

cmd.ExecuteNonQuery();

Conn.Close();

TextBox1.Text = "";

TextBox2.Text = "";

TextBox3.Text = "";

TextBox4.Text = "";

TextBox5.Text = "";

TextBox6.Text = "";

TextBox7.Text = "";

TextBox8.Text = "";

TextBox9.Text = "";

Label8.Visible = true;

Label8.Text = " Inserted Data Sucessfull ...!!! ";

}

catch

{

Label8.Text = " Doesn't Save Data...??";

}

}

}

}

 


Answers (11)