Exemplo n.º 1
0
 public static void SetSqlNullableInt16(this SqlDataRecord sdr, int index, short?value)
 {
     if (value.HasValue)
     {
         sdr.SetSqlInt16(index, value.GetValueOrDefault());
     }
     else
     {
         sdr.SetDBNull(index);
     }
 }
Exemplo n.º 2
0
            IEnumerator <SqlDataRecord> IEnumerable <SqlDataRecord> .GetEnumerator()
            {
                SqlDataRecord sdr = new SqlDataRecord(
                    new SqlMetaData("KeyField", SqlDbType.SmallInt),
                    new SqlMetaData("Description", SqlDbType.VarChar, 20),
                    new SqlMetaData("DisplayOrder", SqlDbType.SmallInt),
                    new SqlMetaData("OKToDelete", SqlDbType.Bit),
                    new SqlMetaData("UpdateYN", SqlDbType.Bit),
                    new SqlMetaData("DeletedYN", SqlDbType.Bit));

                foreach (EnrollmentType i in this)
                {
                    sdr.SetSqlInt16(0, i.KeyField);
                    sdr.SetString(1, i.Description);
                    sdr.SetSqlNullableInt16(2, i.DisplayOrder);
                    sdr.SetBoolean(3, i.OKToDelete);
                    sdr.SetBoolean(4, i.UpdateYN);
                    sdr.SetBoolean(5, i.DeleteYN);
                    yield return(sdr);
                }
            }
Exemplo n.º 3
0
            IEnumerator <SqlDataRecord> IEnumerable <SqlDataRecord> .GetEnumerator()
            {
                SqlDataRecord sdr = new SqlDataRecord(
                    new SqlMetaData("KeyField", SqlDbType.SmallInt),
                    new SqlMetaData("description", SqlDbType.VarChar, 30),
                    new SqlMetaData("MaxStudents", SqlDbType.Int),
                    new SqlMetaData("DeletedYN", SqlDbType.Bit),
                    new SqlMetaData("UpdateYN", SqlDbType.Bit),
                    new SqlMetaData("OKToDelete", SqlDbType.Bit));

                foreach (Room i in this)
                {
                    sdr.SetSqlInt16(0, i.KeyField);
                    sdr.SetString(1, i.description);
                    sdr.SetSqlNullableInt32(2, i.MaxStudents);
                    sdr.SetBoolean(3, i.DeleteYN);
                    sdr.SetBoolean(4, i.UpdateYN);
                    sdr.SetBoolean(5, i.OKToDelete);
                    yield return(sdr);
                }
            }
        public void SqlRecordFillTest()
        {
            SqlMetaData[] metaData = new SqlMetaData[]
            {
                new SqlMetaData("col1", SqlDbType.Bit),
                new SqlMetaData("col2", SqlDbType.TinyInt),
                new SqlMetaData("col3", SqlDbType.VarBinary, 1000),
                new SqlMetaData("col4", SqlDbType.NVarChar, 1000),
                new SqlMetaData("col5", SqlDbType.DateTime),
                new SqlMetaData("col6", SqlDbType.Float),
                new SqlMetaData("col7", SqlDbType.UniqueIdentifier),
                new SqlMetaData("col8", SqlDbType.SmallInt),
                new SqlMetaData("col9", SqlDbType.Int),
                new SqlMetaData("col10", SqlDbType.BigInt),
                new SqlMetaData("col11", SqlDbType.Real),
                new SqlMetaData("col12", SqlDbType.Decimal),
                new SqlMetaData("col13", SqlDbType.Money),
                new SqlMetaData("col14", SqlDbType.Variant)
            };

            SqlDataRecord record = new SqlDataRecord(metaData);

            for (int i = 0; i < record.FieldCount; i++)
            {
                Assert.Equal($"col{i + 1}", record.GetName(i));
            }

            record.SetBoolean(0, true);
            Assert.Equal(true, record.GetBoolean(0));

            record.SetByte(1, 1);
            Assert.Equal(1, record.GetByte(1));

            byte[] bb1 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            byte[] bb2 = new byte[5];
            record.SetSqlBinary(2, new SqlBinary(new byte[0]));
            record.SetBytes(2, 0, bb1, 0, 3);
            record.SetBytes(2, 2, bb1, 6, 3);

            // Verify the length of the byte array
            Assert.Equal(5, record.GetBytes(2, 0, bb2, 0, 5));

            Assert.Equal(5, record.GetBytes(2, 0, null, 0, 0));

            byte[] expected = new byte[] { 1, 2, 7, 8, 9 };
            Assert.Equal <byte>(expected, bb2);

            char[] cb1 = new char[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g' };
            char[] cb2 = new char[5];
            record.SetChars(3, 0, cb1, 0, 3);
            record.SetChars(3, 2, cb1, 4, 3);

            char[] expectedValue = new char[] { 'a', 'b', 'e', 'f', 'g' };
            Assert.Equal(expectedValue.Length, record.GetChars(3, 0, cb2, 0, 5));
            Assert.Equal <char>(expectedValue, new string(cb2, 0, (int)record.GetChars(3, 0, null, 0, 0)));

            record.SetString(3, "");
            string xyz = "xyz";

            record.SetString(3, "xyz");
            Assert.Equal(xyz, record.GetString(3));
            Assert.Equal(xyz.Length, record.GetChars(3, 0, cb2, 0, 5));
            Assert.Equal(xyz, new string(cb2, 0, (int)record.GetChars(3, 0, null, 0, 0)));

            record.SetChars(3, 2, cb1, 4, 3);
            Assert.Equal(5, record.GetChars(3, 0, cb2, 0, 5));

            string interleavedResult = "xyefg";

            Assert.Equal(interleavedResult, new string(cb2, 0, (int)record.GetChars(3, 0, null, 0, 0)));
            Assert.Equal(interleavedResult, record.GetString(3));

            record.SetSqlDateTime(4, SqlDateTime.MaxValue);
            Assert.Equal(SqlDateTime.MaxValue, record.GetSqlDateTime(4));

            record.SetSqlDouble(5, SqlDouble.MaxValue);
            Assert.Equal(SqlDouble.MaxValue, record.GetSqlDouble(5));

            SqlGuid guid = new SqlGuid("F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4");

            record.SetSqlGuid(6, guid);
            Assert.Equal(guid, record.GetSqlGuid(6));

            record.SetSqlInt16(7, SqlInt16.MaxValue);
            Assert.Equal(SqlInt16.MaxValue, record.GetSqlInt16(7));

            record.SetSqlInt32(8, SqlInt32.MaxValue);
            Assert.Equal(SqlInt32.MaxValue, record.GetSqlInt32(8));

            record.SetSqlInt64(9, SqlInt64.MaxValue);
            Assert.Equal(SqlInt64.MaxValue, record.GetSqlInt64(9));

            record.SetSqlSingle(10, SqlSingle.MinValue);
            Assert.Equal(SqlSingle.MinValue, record.GetSqlSingle(10));

            record.SetSqlDecimal(11, SqlDecimal.Null);
            record.SetSqlDecimal(11, SqlDecimal.MaxValue);
            Assert.Equal(SqlDecimal.MaxValue, record.GetSqlDecimal(11));

            record.SetSqlMoney(12, SqlMoney.MaxValue);
            Assert.Equal(SqlMoney.MaxValue, record.GetSqlMoney(12));


            // Try adding different values to SqlVariant type
            for (int i = 0; i < record.FieldCount - 1; ++i)
            {
                object valueToSet = record.GetSqlValue(i);
                record.SetValue(record.FieldCount - 1, valueToSet);
                object o = record.GetSqlValue(record.FieldCount - 1);

                if (o is SqlBinary)
                {
                    Assert.Equal <byte>(((SqlBinary)valueToSet).Value, ((SqlBinary)o).Value);
                }
                else
                {
                    Assert.Equal(valueToSet, o);
                }

                record.SetDBNull(record.FieldCount - 1);
                Assert.Equal(DBNull.Value, record.GetSqlValue(record.FieldCount - 1));

                record.SetDBNull(i);
                Assert.Equal(DBNull.Value, record.GetValue(i));
            }
        }
Exemplo n.º 5
0
            IEnumerator <SqlDataRecord> IEnumerable <SqlDataRecord> .GetEnumerator()
            {
                SqlDataRecord sdr = new SqlDataRecord(
                    new SqlMetaData("AddressFK", SqlDbType.SmallInt),
                    new SqlMetaData("age", SqlDbType.SmallInt, 30),
                    new SqlMetaData("Church", SqlDbType.VarChar),
                    new SqlMetaData("Denomination", SqlDbType.VarChar),
                    new SqlMetaData("DisabilitiesExplanation", SqlDbType.VarChar),
                    new SqlMetaData("DOB", SqlDbType.Date),
                    new SqlMetaData("EducationFK", SqlDbType.SmallInt),
                    new SqlMetaData("EducationMajor", SqlDbType.VarChar),
                    new SqlMetaData("Email", SqlDbType.VarChar),
                    new SqlMetaData("EmergencyNotify", SqlDbType.VarChar),
                    new SqlMetaData("Employer", SqlDbType.VarChar),
                    new SqlMetaData("EmployerPhone", SqlDbType.VarChar),
                    new SqlMetaData("EnrollmentTypeFK", SqlDbType.SmallInt),
                    new SqlMetaData("FamilyKey", SqlDbType.SmallInt),
                    new SqlMetaData("FirstName", SqlDbType.VarChar),
                    new SqlMetaData("Gender", SqlDbType.VarChar),
                    new SqlMetaData("Grade", SqlDbType.SmallInt),
                    new SqlMetaData("HasLearningDisabilities", SqlDbType.Bit),
                    new SqlMetaData("HasPhysicalDisabilities", SqlDbType.Bit),
                    new SqlMetaData("InHSLDA", SqlDbType.Bit),
                    new SqlMetaData("inMTHEA", SqlDbType.Bit),
                    new SqlMetaData("IsPrimaryAddress", SqlDbType.Bit),
                    new SqlMetaData("keyfield", SqlDbType.SmallInt),
                    new SqlMetaData("LastName", SqlDbType.VarChar),
                    new SqlMetaData("LastYrSchool", SqlDbType.VarChar),
                    new SqlMetaData("PersonFK", SqlDbType.SmallInt),
                    new SqlMetaData("PrimaryInsurance", SqlDbType.VarChar),
                    new SqlMetaData("PrimaryPhone", SqlDbType.VarChar),
                    new SqlMetaData("SecondaryPhone", SqlDbType.VarChar),
                    new SqlMetaData("SSN", SqlDbType.VarChar),
                    new SqlMetaData("SupportGroupOrCoop", SqlDbType.VarChar),
                    new SqlMetaData("WillGraduate", SqlDbType.Bit));

                foreach (People i in this)
                {
                    sdr.SetSqlInt16(0, i.AddressFK);
                    sdr.SetSqlInt16(1, i.age);
                    sdr.SetString(3, i.Church);
                    sdr.SetString(4, i.Denomination);
                    sdr.SetString(5, i.DisabilitiesExplanation);
                    sdr.SetNullableDateTime(5, i.DOB);
                    sdr.SetSqlInt16(5, i.EducationFK);
                    sdr.SetString(5, i.EducationMajor);
                    sdr.SetString(5, i.Email);
                    sdr.SetString(5, i.EmergencyNotify);
                    sdr.SetString(5, i.Employer);
                    sdr.SetString(5, i.EmployerPhone);
                    sdr.SetSqlInt16(5, i.EnrollmentTypeFK);
                    // sdr.SetSqlInt16(5, i.FamilyKey);
                    sdr.SetString(5, i.FirstName);
                    sdr.SetString(5, i.Gender);
                    sdr.SetSqlInt16(5, i.Grade);
                    sdr.SetBoolean(5, i.HasLearningDisabilities);
                    sdr.SetBoolean(5, i.HasPhysicalDisabilities);
                    sdr.SetBoolean(5, i.InHSLDA);
                    sdr.SetBoolean(5, i.inMTHEA);
                    sdr.SetBoolean(5, i.IsPrimaryAddress);
                    sdr.SetSqlInt16(5, i.keyfield);
                    sdr.SetString(5, i.LastName);
                    sdr.SetString(5, i.LastYrSchool);
                    sdr.SetSqlInt16(5, i.PersonFK);
                    sdr.SetBoolean(5, i.PrimaryInsurance);
                    sdr.SetString(5, i.PrimaryPhone);
                    sdr.SetString(5, i.SecondaryPhone);
                    sdr.SetString(5, i.SSN);
                    sdr.SetString(5, i.SupportGroupOrCoop);
                    sdr.SetBoolean(5, i.WillGraduate);
                    yield return(sdr);
                }
            }