Guest User

Guest User

  • Tech Writer
  • 529
  • 40.9k

Stored Procedure in Sql Insert Single parameters Muliti textbox Save?

Mar 1 2022 9:53 PM

this Higlight Code Working For Me

try

{

data.openDBConnection();
SqlCommand cmd = new SqlCommand("Sp_RegisterVehicle", data.getDatabaseConnection());
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@ActionType", "SaveData");
cmd.Parameters.AddWithValue("@id", SqlDbType.Int).Value = empid;
cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = txt_firstname.Text;

}

int numres = cmd.ExecuteNonQuery();
                if (numres > 0)
                {
                    MessageBox.Show("Data Saved Successfully ", "Vehicle Register", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
                else
                {
                    MessageBox.Show("Data Saved Failed", "Vehicle Register", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                DialogResult = MessageBox.Show("Error" + ex.Message);
            }
            finally
            {
                data.closeDBConnection();
            }

But I Will try Single Parmerters three diffrent textbox value Save In Single Table Colums For Example

this is Example of Name

1.John
  Clark
  Davide

I Want To Save Like this on Single Parmeter but i have 2 more txetBox

cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = txt_firstname.Text;

cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = txt_firstname1.Text;

cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = txt_firstname2.Text;

Save In Single ID but colums Format 

1.txt_firstname.Text = value  John
  txt_firstname1.Text  = Clark
 txt_firstname2.Text = Davide

i want to save like this image


Answers (6)