c# - SQL query data to cshtml -
I am not very good but I am trying to think that there is something that I do not understand anywhere ... I am trying to get data from a DB, like how many lines are given "X"? Simple look I know the SQL statement for this, there are several walkthroughs around but I do not know how to show it on a page.
if (request .QueryString ["RNum"]. IsEmpty ()) {searchTerm = Request.QueryString ["RNum"]; SelectCommand2 = "SELECT COUNT (NoEmpl) from DTool where NOEmpl = @ 0"; } Calculation var = db.qualityValue (selectcommand2, searchTerm); How can I show it on a page with a submit button to send the query?
just try
searchTerm = Request.QueryString ["RNum "]; String sqlSelect = "SELECT COUNT (NoEmpl) from DTool where NOEmpl = @NEEmpl"; SqlConnection sqlConnection = New SqlConnection (sqlConnectString); SqlCommand sqlCommand = new SqlCommand (sqlSelect, sqlConnection); // Set SqlDbType based on your DB column data-type sqlCommand.Parameters.Add ("@ NoEmpl", System.Data.SqlDbType.Varcahr); SqlCommand.Parameters ["@ NoEmpl"]. Value = searchTerm; Using or
(SqlConnection connection = new SqlConnection (connectionString)) {connection.Open (); (Add new SqlParameter to SqlCommand command = new SqlCommand ("SET COUNT (NoEmpl) from DTool, where NOEmpl = @NEEmpl", connection)) // // command. // command.Parameters.Add (new SqlParameter ("@ NoEmpl", searchTerm)); Read // // SELECT results in the results. // SqlDataReader Reader = command.ExecuteReader (); // read here}}
Comments
Post a Comment