如何使用mvc4中的枚举值创建下拉列表
我有一个类Language.cs
public enum Language {
English = 0
}
Run Code Online (Sandbox Code Playgroud)
我的财产是
public Language Language { get; set; }
Run Code Online (Sandbox Code Playgroud)
我将如何通过下拉列表调用我的视图
我在C#中编写数据库命令,如下所示
using (SqlConnection con = new SqlConnection(Config.ConnectionString))
{
using (SqlCommand cmd = new SqlCommand("INSERT INTO ProjectDetails(pro_name,pro_location,pro_briefdesc,pro_desc,pro_res,pro_contact,pro_add,pro_email,pro_phone) VALUES (@name,@loc,@brief,@desc,@res,@cont,@add,@email,@ph)", con))
{
cmd.Parameters.AddWithValue("@name",pro_name);
cmd.Parameters.AddWithValue("@loc",pro_location );
cmd.Parameters.AddWithValue("@brief",pro_briefdesc);
cmd.Parameters.AddWithValue("@desc", pro_desc);
cmd.Parameters.AddWithValue("@res",pro_res);
cmd.Parameters.AddWithValue("@cont",pro_contact);
cmd.Parameters.AddWithValue("@add",pro_add);
cmd.Parameters.AddWithValue("@email",pro_email);
cmd.Parameters.AddWithValue("@ph",pro_phone );
con.Open();
int modified = cmd.ExecuteNonQuery();
if (con.State == System.Data.ConnectionState.Open) con.Close();
return modified;
}
}
Run Code Online (Sandbox Code Playgroud)
如何通常打开和关闭我的连接 - 即最小的代码重复(重复).