ASP.Netで空のプロジェクトを作成してから、ビュー、コントローラー、およびモデルを手動で追加しました。次に、SQLServerをModelクラスに接続します。どうすればいいですか?
1118 次
1 に答える
0
try with this code, this code contain select query for just example
// Is your string connection to your database and server
string connectionString = ""; //connection to your database
//Create a connection to your database
//using bloc , in order to destruct connection object in the end of treatment
using (SqlConnection connection = new SqlConnection(connectionString))
{
//Create object command who contain your query sql, permit you to get data or //insert on update or delete data
using (SqlCommand command= connection.CreateCommand())
{
//for example a query, who select data from table in your databse,
command.CommandText = "SELECT * FROM Table where col = @ParameterTest";
//for exxample a parameter for your query
command.Parameters.Add("@ParameterTest", 123); //your test value
//after create connection you must open this
command.Connection.Open();
//get data in reader, structure for readin datas
var reader = command.ExecuteDataReader();
}
}
于 2012-06-27T11:38:50.933 に答える