Going Mobile Listing #2: System.Data.SqlClient

using (SqlConnection conn = new SqlConnection(_connect))
{
  using (SqlCommand cmd = new SqlCommand())
  {
    cmd.CommandText = "pr_PatientInsert";
    cmd.CommandType = CommandType.StoredProcedure;

    SqlParameter param = new SqlParameter();
    param.ParameterName = "@Firstname";
    param.SqlDbType = SqlDbType.VarChar;
    param.Direction = ParameterDirection.Input;
    param.Value = "John";
    cmd.Parameters.Add(param);

    param = new SqlParameter();
    param.ParameterName = "@LastName";
    param.SqlDbType = SqlDbType.VarChar;
    param.Direction = ParameterDirection.Input;
    param.Value = "Doe";
    cmd.Parameters.Add(param);

    param = new SqlParameter();
    param.ParameterName = "@PatientNumber";
    param.SqlDbType = SqlDbType.VarChar;
    param.Direction = ParameterDirection.Input;
    param.Value = "100100100";
    cmd.Parameters.Add(param);

    cmd.Connection = conn;
    conn.Open();
    object obj = cmd.ExecuteScalar();
    int id = Convert.ToInt32(obj);
 
    String newId = id.ToString();
  }
}
comments powered by Disqus
Upcoming Events

.NET Insight

Sign up for our newsletter.

I agree to this site's Privacy Policy.