当前位置: 首页>>代码示例>>C#>>正文


C# SqlDataReader.GetSqlValue方法代码示例

本文整理汇总了C#中System.Data.SqlClient.SqlDataReader.GetSqlValue方法的典型用法代码示例。如果您正苦于以下问题:C# SqlDataReader.GetSqlValue方法的具体用法?C# SqlDataReader.GetSqlValue怎么用?C# SqlDataReader.GetSqlValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Data.SqlClient.SqlDataReader的用法示例。


在下文中一共展示了SqlDataReader.GetSqlValue方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Cliente

        public void Cliente()
        {
            var foo = System.Configuration.ConfigurationSettings.AppSettings["MyConnection"];
            //sql query
            con = new SqlConnection(foo);
            con.Open();
            string CommandText = "SELECT TOP 1 * FROM dbo.Cliente ORDER BY ClienteId DESC ";
            cmd = new SqlCommand(CommandText);
            cmd.Connection = con;
            rdr = cmd.ExecuteReader();
            rdr.Read();
            string valor = rdr.GetSqlValue(0).ToString(); //Es 0 porque se lee el valor [ClienteId] de la tabla dbo.Cliente
            int valorr = int.Parse(valor.Substring(9)) + 1;
            MessageBox.Show("TROMPOTIJ" + valorr.ToString()); con.Close();

            var myParameters = new SqlParameter[]
            {
                new SqlParameter("nombre", "valor")
            };

            var command = new SqlCommand()
            {
                CommandType = System.Data.CommandType.StoredProcedure,
                CommandText = "ClienteInsert",
                Connection = con
            };
            command.Parameters.Add(myParameters);
            cmd.ExecuteNonQuery();
        }
开发者ID:cgdelatorre,项目名称:ElTrompo,代码行数:29,代码来源:Alta.cs

示例2: Page_Load

 protected void Page_Load(object sender, EventArgs e)
 {
     if (Session["user"] == null)
         Response.Redirect("Login.aspx");
     Label5.Text = Session["CheckNo"].ToString();
     Label17.Text = Session["WorkSymbol"].ToString();
     Label8.Text = Session["CheckerName"].ToString();
     Label12.Text = Convert.ToDateTime(Session["Checktime"].ToString()).ToString("yyyy-MM-dd");
     string sql = "select ShopName,GroupName,TeamName from Management where ID = @ID";
     cmd = new SqlCommand(sql, con);
     cmd.Parameters.AddWithValue("@ID", Session["ChckerID"]);
     try
     {
         if (con.State == ConnectionState.Open)
             con.Close();
         con.Open();
         sdr = cmd.ExecuteReader();
         string show = null;
         if (sdr.Read())
         {
             show = sdr.GetSqlValue(0).ToString();
             show += sdr.GetSqlValue(1).ToString();
             show += sdr.GetSqlValue(2).ToString();
             if (show == "")
                 show = "GM";
         }
         Label10.Text = show;
     }
     catch (Exception ee)
     {
         Response.Write("<script language='JavaScript'>alert('" + ee.Message + "!')</script>");
         return;
     }
     finally
     {
         con.Close();
     }
     GridView1.Attributes.Add("style", "word-break:keep-all;word-wrap:normal");
 }
开发者ID:yangpeiren,项目名称:hello-world,代码行数:39,代码来源:Create_PDCA.aspx.cs

示例3: FillCompatibleITypedSettersFromReader


//.........这里部分代码省略.........
                            SetSqlChars_LengthChecked( sink, setters, i, metaData[i], reader.GetSqlChars(i), 0 );
                            break;
                        case SqlDbType.DateTime:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.DateTime ) );
                            SetDateTime_Checked( sink, setters, i, metaData[i], reader.GetDateTime(i) );
                            break;
                        case SqlDbType.Decimal:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.SqlDecimal ) );
                            SetSqlDecimal_Unchecked( sink, setters, i, reader.GetSqlDecimal(i) );
                            break;
                        case SqlDbType.Float:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.Double ) );
                            SetDouble_Unchecked( sink, setters, i, reader.GetDouble(i) );
                            break;
                        case SqlDbType.Image:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.SqlBytes ) );
                            SetSqlBytes_LengthChecked( sink, setters, i, metaData[i], reader.GetSqlBytes(i), 0 );
                            break;
                        case SqlDbType.Int:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.Int32 ) );
                            SetInt32_Unchecked( sink, setters, i, reader.GetInt32(i) );
                            break;
                        case SqlDbType.Money:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.SqlMoney ) );
                            SetSqlMoney_Unchecked( sink, setters, i, metaData[i], reader.GetSqlMoney(i) );
                            break;
                        case SqlDbType.NChar:
                        case SqlDbType.NText:
                        case SqlDbType.NVarChar:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.SqlChars ) );
                            SetSqlChars_LengthChecked( sink, setters, i, metaData[i], reader.GetSqlChars(i), 0 );
                            break;
                        case SqlDbType.Real:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.Single ) );
                            SetSingle_Unchecked( sink, setters, i, reader.GetFloat(i) );
                            break;
                        case SqlDbType.UniqueIdentifier:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.Guid ) );
                            SetGuid_Unchecked( sink, setters, i, reader.GetGuid(i) );
                            break;
                        case SqlDbType.SmallDateTime:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.DateTime ) );
                            SetDateTime_Checked( sink, setters, i, metaData[i], reader.GetDateTime(i) );
                            break;
                        case SqlDbType.SmallInt:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.Int16 ) );
                            SetInt16_Unchecked( sink, setters, i, reader.GetInt16(i) );
                            break;
                        case SqlDbType.SmallMoney:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.SqlMoney ) );
                            SetSqlMoney_Checked( sink, setters, i, metaData[i], reader.GetSqlMoney(i) );
                            break;
                        case SqlDbType.Text:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.SqlChars ) );
                            SetSqlChars_LengthChecked( sink, setters, i, metaData[i], reader.GetSqlChars(i), 0 );
                            break;
                        case SqlDbType.Timestamp:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.SqlBytes ) );
                            SetSqlBytes_LengthChecked( sink, setters, i, metaData[i], reader.GetSqlBytes(i), 0 );
                            break;
                        case SqlDbType.TinyInt:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.Byte ) );
                            SetByte_Unchecked( sink, setters, i, reader.GetByte(i) );
                            break;
                        case SqlDbType.VarBinary:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.SqlBytes ) );
                            SetSqlBytes_LengthChecked( sink, setters, i, metaData[i], reader.GetSqlBytes(i), 0 );
                            break;
                        case SqlDbType.VarChar:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.String ) );
                            SetSqlChars_LengthChecked( sink, setters, i, metaData[i], reader.GetSqlChars(i), 0 );
                            break;
                        case SqlDbType.Xml:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.SqlXml ) );
                            SetSqlXml_Unchecked( sink, setters, i, reader.GetSqlXml(i) );
                            break;
                        case SqlDbType.Variant:
                            object o = reader.GetSqlValue(i);
                            ExtendedClrTypeCode typeCode = MetaDataUtilsSmi.DetermineExtendedTypeCode( o );
                            SetCompatibleValue( sink, setters, i, metaData[i], o, typeCode, 0 );
                            break;
                            
                        case SqlDbType.Udt:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.SqlBytes ) );
                            SetSqlBytes_LengthChecked( sink, setters, i, metaData[i], reader.GetSqlBytes(i), 0 );
                            break;

                        default:
                            // In order for us to get here we would have to have an 
                            // invalid instance of SqlDbType, or one would have to add 
                            // new member to SqlDbType without adding a case in this 
                            // switch, hence the assert - it must be 

                            Debug.Assert( false, "unsupported DbType:" + metaData[i].SqlDbType.ToString() );
                            throw ADP.NotSupported();
                            
                    }
                }
            }
        }
开发者ID:uQr,项目名称:referencesource,代码行数:101,代码来源:ValueUtilsSmi.cs

示例4: CompleteExecuteScalar

 private object CompleteExecuteScalar(SqlDataReader ds, bool returnSqlValue)
 {
     object obj2 = null;
     try
     {
         if (!ds.Read() || (ds.FieldCount <= 0))
         {
             return obj2;
         }
         if (returnSqlValue)
         {
             return ds.GetSqlValue(0);
         }
         obj2 = ds.GetValue(0);
     }
     finally
     {
         ds.Close();
     }
     return obj2;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:21,代码来源:SqlCommand.cs

示例5: FillCompatibleITypedSettersFromReader


//.........这里部分代码省略.........
                 continue;
             }
             case SqlDbType.Float:
             {
                 SetDouble_Unchecked(sink, setters, i, reader.GetDouble(i));
                 continue;
             }
             case SqlDbType.Image:
             {
                 SetSqlBytes_LengthChecked(sink, setters, i, metaData[i], reader.GetSqlBytes(i), 0);
                 continue;
             }
             case SqlDbType.Int:
             {
                 SetInt32_Unchecked(sink, setters, i, reader.GetInt32(i));
                 continue;
             }
             case SqlDbType.Money:
             {
                 SetSqlMoney_Unchecked(sink, setters, i, metaData[i], reader.GetSqlMoney(i));
                 continue;
             }
             case SqlDbType.NChar:
             case SqlDbType.NText:
             case SqlDbType.NVarChar:
             {
                 SetSqlChars_LengthChecked(sink, setters, i, metaData[i], reader.GetSqlChars(i), 0);
                 continue;
             }
             case SqlDbType.Real:
             {
                 SetSingle_Unchecked(sink, setters, i, reader.GetFloat(i));
                 continue;
             }
             case SqlDbType.UniqueIdentifier:
             {
                 SetGuid_Unchecked(sink, setters, i, reader.GetGuid(i));
                 continue;
             }
             case SqlDbType.SmallDateTime:
             {
                 SetDateTime_Checked(sink, setters, i, metaData[i], reader.GetDateTime(i));
                 continue;
             }
             case SqlDbType.SmallInt:
             {
                 SetInt16_Unchecked(sink, setters, i, reader.GetInt16(i));
                 continue;
             }
             case SqlDbType.SmallMoney:
             {
                 SetSqlMoney_Checked(sink, setters, i, metaData[i], reader.GetSqlMoney(i));
                 continue;
             }
             case SqlDbType.Text:
             {
                 SetSqlChars_LengthChecked(sink, setters, i, metaData[i], reader.GetSqlChars(i), 0);
                 continue;
             }
             case SqlDbType.Timestamp:
             {
                 SetSqlBytes_LengthChecked(sink, setters, i, metaData[i], reader.GetSqlBytes(i), 0);
                 continue;
             }
             case SqlDbType.TinyInt:
             {
                 SetByte_Unchecked(sink, setters, i, reader.GetByte(i));
                 continue;
             }
             case SqlDbType.VarBinary:
             {
                 SetSqlBytes_LengthChecked(sink, setters, i, metaData[i], reader.GetSqlBytes(i), 0);
                 continue;
             }
             case SqlDbType.VarChar:
             {
                 SetSqlChars_LengthChecked(sink, setters, i, metaData[i], reader.GetSqlChars(i), 0);
                 continue;
             }
             case SqlDbType.Variant:
             {
                 object sqlValue = reader.GetSqlValue(i);
                 ExtendedClrTypeCode typeCode = MetaDataUtilsSmi.DetermineExtendedTypeCode(sqlValue);
                 SetCompatibleValue(sink, setters, i, metaData[i], sqlValue, typeCode, 0);
                 continue;
             }
             case SqlDbType.Xml:
             {
                 SetSqlXml_Unchecked(sink, setters, i, reader.GetSqlXml(i));
                 continue;
             }
             case SqlDbType.Udt:
             {
                 SetSqlBytes_LengthChecked(sink, setters, i, metaData[i], reader.GetSqlBytes(i), 0);
                 continue;
             }
         }
         throw ADP.NotSupported();
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:101,代码来源:ValueUtilsSmi.cs

示例6: GetSqlValue_Index_Invalid

		public void GetSqlValue_Index_Invalid ()
		{
			cmd.CommandText = "Select id, type_tinyint, null from numeric_family where id=1";
			reader = cmd.ExecuteReader ();
			reader.Read ();

			try {
				reader.GetSqlValue (-1);
				Assert.Fail ("#A1");
			} catch (IndexOutOfRangeException ex) {
				// Index was outside the bounds of the array
				Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#A2");
				Assert.IsNull (ex.InnerException, "#A3");
				Assert.IsNotNull (ex.Message, "#A4");
			}

			try {
				reader.GetSqlValue (3);
				Assert.Fail ("#B1");
			} catch (IndexOutOfRangeException ex) {
				// Index was outside the bounds of the array
				Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#B2");
				Assert.IsNull (ex.InnerException, "#B3");
				Assert.IsNotNull (ex.Message, "#B4");
			}
		}
开发者ID:Profit0004,项目名称:mono,代码行数:26,代码来源:SqlDataReaderTest.cs

示例7: GetSqlValue

		public void GetSqlValue ()
		{
			cmd.CommandText = "Select id, type_tinyint, null from numeric_family where id=1";
			reader = cmd.ExecuteReader ();
			reader.Read ();

			Assert.AreEqual ((byte) 255, ((SqlByte) reader.GetSqlValue (1)).Value, "#1");
			//Assert.AreEqual (DBNull.Value, reader.GetSqlValue(2), "#2");

			reader.Close ();
		}
开发者ID:Profit0004,项目名称:mono,代码行数:11,代码来源:SqlDataReaderTest.cs

示例8: WriteCustomers

        /// <summary>
        /// Loop through the SqlDataReader and write each Customer
        /// record to the XMLWriter.
        /// </summary>
        /// <param name="inReader">The SqlDataReader that contains
        /// the query results from a Customer table.</param>
        /// <param name="inWriter">The XmlWriter that will receive
        /// the XML-formatter Customer records.</param>
        private static void WriteCustomers(SqlDataReader inReader, XmlWriter inWriter)
        {
            inWriter.WriteStartElement("Customers");

            while (inReader.Read())
            {
                inWriter.WriteStartElement("Customer");

                // Find the CustomerID column and use its
                // value as the "id" attribute.
                int idColumn = inReader.GetOrdinal("CustomerID");
                int id = inReader.GetInt32(idColumn);
                inWriter.WriteAttributeString("id", id.ToString());

                // All the other columns are child elements
                // of the Customer element.
                for (int column = 0; column < inReader.FieldCount; ++column)
                {
                    if (column == idColumn)
                        continue;
                    string name = inReader.GetName(column);
                    string value = inReader.GetSqlValue(column).ToString();

                    inWriter.WriteElementString(name, value);
                }

                inWriter.WriteEndElement();
            }

            inWriter.WriteEndElement();
        }
开发者ID:nstublen,项目名称:jccc-csharp-samples,代码行数:39,代码来源:Program.cs

示例9: CopyReader

    // Needs reader to be positioned on the first row
    private static void CopyReader(SqlDataReader reader, SqlConnection outCon,
        string outTable, SqlParameter[] paramList)
    {
        using (SqlCommand outCmd = outCon.CreateCommand())
        try {
            System.Text.StringBuilder insertCmdStr =
                new System.Text.StringBuilder();

            insertCmdStr.AppendFormat("INSERT INTO {0} VALUES (", outTable);

            for (int i = 0; i < paramList.GetLength(0); i++) {
                if (i > 0)
                    insertCmdStr.Append(", ");

                insertCmdStr.AppendFormat("@col{0}", i);
                outCmd.Parameters.Add(paramList[i]);
            }

            insertCmdStr.Append(")");

            outCmd.CommandText = insertCmdStr.ToString();

            // If this throws, the most likely culprit is one (or more) of the
            // SqlParameters being generated incorrectly in GenerateSchema()
            outCmd.Prepare();

            do {
                for (int i = 0; i < paramList.GetLength(0); i++) {
                    paramList[i].SqlValue = reader.GetSqlValue(i);
                }
                outCmd.ExecuteNonQuery();

                if (sendDebugInfo)
                    SqlContext.Pipe.Send(string.Format("Record sent to {0}",
                            outTable));
            } while (reader.Read());

            outCmd.Parameters.Clear();
        } catch (SqlException e) {
            throw new System.Exception(
                string.Format("Could not send data to {0}", outTable), e);
        }
    }
开发者ID:apenwarr,项目名称:versaplex,代码行数:44,代码来源:AssemblyInfo.cs


注:本文中的System.Data.SqlClient.SqlDataReader.GetSqlValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。