本文整理汇总了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();
}
示例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");
}
示例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();
}
}
}
}
示例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;
}
示例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();
}
}
示例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");
}
}
示例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 ();
}
示例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();
}
示例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);
}
}