Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/446.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我想在asp.net mvc 3.1(不带ORM)中显示sql表中的特定行_Javascript_Asp.net Mvc_C# 4.0 - Fatal编程技术网

Javascript 我想在asp.net mvc 3.1(不带ORM)中显示sql表中的特定行

Javascript 我想在asp.net mvc 3.1(不带ORM)中显示sql表中的特定行,javascript,asp.net-mvc,c#-4.0,Javascript,Asp.net Mvc,C# 4.0,我有一个名为products的表,其中有9行产品,它们有自己的unqiue productId。我想展示productId=3的产品。我怎样才能做到这一点,或者你知道哪一辆面包车会给我讲解它吗?MVC-模型视图控制器,实际上MVC不需要任何数据库。假设您有对象模型、模型视图和控制器来执行您需要的任何操作。所以,要将对象模型持久化到数据库中,不需要使用ORM。您可以调用DB存储过程、直接表、SQL计划文本来持久化数据 用于执行存储过程的示例 static void GetSalesByCatego

我有一个名为products的表,其中有9行产品,它们有自己的unqiue productId。我想展示productId=3的产品。我怎样才能做到这一点,或者你知道哪一辆面包车会给我讲解它吗?

MVC-模型视图控制器,实际上MVC不需要任何数据库。假设您有对象模型、模型视图和控制器来执行您需要的任何操作。所以,要将对象模型持久化到数据库中,不需要使用ORM。您可以调用DB存储过程、直接表、SQL计划文本来持久化数据

用于执行存储过程的示例

static void GetSalesByCategory(string connectionString,
    string categoryName)
{
    using (SqlConnection connection = new SqlConnection(connectionString))
    {
        // Create the command and set its properties.
        SqlCommand command = new SqlCommand();
        command.Connection = connection;
        command.CommandText = "SalesByCategory";
        command.CommandType = CommandType.StoredProcedure;

        // Add the input parameter and set its properties.
        SqlParameter parameter = new SqlParameter();
        parameter.ParameterName = "@CategoryName";
        parameter.SqlDbType = SqlDbType.NVarChar;
        parameter.Direction = ParameterDirection.Input;
        parameter.Value = categoryName;

        // Add the parameter to the Parameters collection.
        command.Parameters.Add(parameter);

        // Open the connection and execute the reader.
        connection.Open();
        using (SqlDataReader reader = command.ExecuteReader())
        {
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    Console.WriteLine("{0}: {1:C}", reader[0], reader[1]);
                }
            }
            else
            {
                Console.WriteLine("No rows found.");
            }
            reader.Close();
        }
    }
}
命令类型枚举

StoredProcedure     
TableDirect
Text