0

I am totally new to ASP.NET and C#, and I am designing a web form. The user gives me some inputs, let's say keyvalue, and I have to query a database using that parameter.

I have seen that it's possible to run a SQL query inside C#. In that example, however, the query string is fixed:

string queryString = "SELECT * FROM This.Table WHERE keyvalue = 'WINNIPEG'"

What if my keyvalue comes from user input instead? Can I do something like:

string keyvalue = txtInputCell.Text
string queryString = "SELECT * FROM Table WHERE key = keyvalue"
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Zizzipupp
  • 1,301
  • 1
  • 11
  • 27
  • 4
    There are a *lot* of ASP.NET and ADO.NET tutorials that show how to handle user input and how to execute a query. Every `Getting Started` tutorial in learn.microsoft.com shows how to read data from forms and how to call the database. Which stack are you using? WebForms? ASP.NET MVC? Razor Pages? – Panagiotis Kanavos Oct 14 '19 at 16:23
  • This is an empty page built as a web form. – Zizzipupp Oct 14 '19 at 16:28

0 Answers0