Alessandro Minneci Alessandro Minneci - 6 months ago 14
SQL Question

How can I save my Textbox content in a database? Textbox is programmed in HTML and CSS

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

My ConnectionString is already programmed
enter image description here
I coded my textbox as following:

enter image description here

How do i have to integrate my C# in my Html code so it saves my Content?

Thanks for your time <3

Answer

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

Comments