Connecting SQL data from MVCapplication without EF
string connectionString = "Server=KCPC\\SQLEXPRESS;Database=Optician;User ID=sa;Password=123456;Trusted_Connection=False";
SqlConnection cnn = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand();
cmd.Connection = cnn;
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.CommandText = "spPatientList";
cnn.Open();
SqlDataReader data = cmd.ExecuteReader();
while (data.Read())
{
string sd = data["PatientCode"].ToString();
}
cnn.Close();
SqlConnection cnn = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand();
cmd.Connection = cnn;
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.CommandText = "spPatientList";
cnn.Open();
SqlDataReader data = cmd.ExecuteReader();
while (data.Read())
{
string sd = data["PatientCode"].ToString();
}
cnn.Close();
Comments
Post a Comment