0

I have a fully finished Frontend of my Web Application, now I have to save the textbox content in my Database(SQL) which I created in Visual Studio.

My ConnectionString is already programmed Image I coded my textbox as following:

My Code

How do I have to integrate my C# in my HTML code so it saves my content?

Thanks for your time

3
  • 2
    What exactly do you need to know? Have you created a table in the database to store those values? Would you want to use Entity Framework or ADO? In order to help, I think we need more content from your question Commented May 18, 2016 at 11:40
  • The Tabels are created, what i need to know: Commented May 18, 2016 at 11:51
  • How to store my Data in the Database. It should save it as soon as i press a "next" button". What i also want to know is how i have to set this all up in my html code Commented May 18, 2016 at 11:53

1 Answer 1

1

Use this in whichever event you want it to execute in:

string con = //your connection string here
string yourTextValue = Passnummer.Text; //This will extract the text from your textbox and store it in a variable
using (string con = new SqlConnection()) {
con.Open();

var command =
    new SqlCommand("INSERT INTO yourTable(columnname) VALUES (@textValue);", con);
command.Parameters.AddWithValue("@textValue", yourTextValue);

command.ExecuteNonQuery();
con.Close();
}

See Here

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your anwer. Do you know any way on how i can save my textbox value, in a variable?
string yourTextValue is your variable in this case So what you do is take say: string yourTextValue = yourtextboxname.Text; this will take what is in your textbox and store it in the variable (as soon as your event is fired) So say you want to do this in a button click, you insert the code above in to the button click method, as soon as you click your button it will look at your textbox and store whatever is currently in there to the variable

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.