将存储过程写入
如何使用SQL Server 2008在Asp.net核心中实现这些?
答案 0 :(得分:0)
首先,尝试通过NuGet获取System.Data.Common和System.Data.SqlClient。获得这些引用后,您就可以开始在应用程序中编写ADO.NET命令:
DataTable dt = new DataTable();
using (SqlConnection sqlConn = new SqlConnection("Your Connection String Here")){
string sql = "YourStoredProcedureName";
using (SqlCommand sqlCmd = new SqlCommand(sql, sqlConn)){
sqlCmd.CommandType = CommandType.StoredProcedure;
sqlCmd.Parameters.AddWithValue("@Param", "SomeValueHereToPass");
sqlConn.Open();
using (SqlDataAdapter sqlAdapter = new SqlDataAdapter(sqlCmd)){
sqlAdapter.Fill(dt);
}
}
}