本文整理汇总了C#中System.Data.SqlClient.SqlDataReader.Read方法的典型用法代码示例。如果您正苦于以下问题:C# SqlDataReader.Read方法的具体用法?C# SqlDataReader.Read怎么用?C# SqlDataReader.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.SqlClient.SqlDataReader
的用法示例。
在下文中一共展示了SqlDataReader.Read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: readTable
public static List<Club> readTable(string SqlQuery, string serverName, string databaseName)
{
myConnection = new SqlConnection(serverName + ";" + databaseName + ";" + "Integrated Security=true");
try
{
myConnection.Open();
myCommand = new SqlCommand(SqlQuery, myConnection);
myReader = myCommand.ExecuteReader();
ClubList.Clear();
while(myReader.Read()) {
//Console.WriteLine(myReader[0].ToString());
//code here to map query output to club objects and put into list
ClubList.Add(new Club
{
id = myReader[0].ToString(),
//name = myReader[1].ToString(),
//address = myReader[2].ToString(),
//city = myReader[3].ToString(),
//state = myReader[4].ToString()
});
}
} catch (Exception e) {
Console.WriteLine(e.ToString());
}
finally
{
myConnection.Close();
}
return ClubList;
}
示例2: button1_Click
private void button1_Click(object sender, EventArgs e)
{
listView1.Items.Clear();
CN = new SqlConnection(cadenaconexion);
CMD = new SqlCommand("SELECT * FROM Prueba", CN);
CMD.CommandType = CommandType.Text;
try
{
CN.Open();
RDR = CMD.ExecuteReader();
while (RDR.Read())
{
ListViewItem lvi = new ListViewItem();
lvi.Text = (string)RDR["id"].ToString();
lvi.SubItems.Add((string)RDR["nombre"]);
listView1.Items.Add(lvi);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
CN.Close();
}
}
示例3: convert
public List<List<String>> convert(SqlDataReader reader)
{
if (reader != null)
{
List<List<String>> list = new List<List<String>>();
while (reader.Read())
{
List<String> tmp = new List<String>();
for (int i = 0; i < reader.FieldCount; i++)
{
string s = "";
try
{
s = reader.GetString(i);
}
catch (SqlNullValueException)
{
s = "null";
}
tmp.Add(s);
}
list.Add(tmp);
}
return list;
}
return null;
}
示例4: loadlist
// Apresentar os registros da pesquisa desejada.
public void loadlist()
{
listBox1.Items.Clear();
listBox2.Items.Clear();
listBox3.Items.Clear();
listBox4.Items.Clear();
listBox5.Items.Clear();
listBox6.Items.Clear();
listBox7.Items.Clear();
conexao.Open();
comando.CommandText = "SELECT * FROM Contatos";
LerDados = comando.ExecuteReader();
if (LerDados.HasRows)
{
while (LerDados.Read())
{
listBox1.Items.Add(LerDados[0].ToString());
listBox2.Items.Add(LerDados[1].ToString());
listBox3.Items.Add(LerDados[2].ToString());
listBox4.Items.Add(LerDados[3].ToString());
listBox5.Items.Add(LerDados[4].ToString());
listBox6.Items.Add(LerDados[5].ToString());
listBox7.Items.Add(LerDados[6].ToString());
}
}
conexao.Close();
}
示例5: ProcessSqlResult
protected override Exception ProcessSqlResult(SqlDataReader reader)
{
Exception nextResultSet = StoreUtilities.GetNextResultSet(base.InstancePersistenceCommand.Name, reader);
if (nextResultSet == null)
{
reader.NextResult();
List<IDictionary<XName, object>> parameters = new List<IDictionary<XName, object>>();
if (reader.Read())
{
do
{
IDictionary<XName, object> item = new Dictionary<XName, object>();
item.Add(WorkflowServiceNamespace.SiteName, reader.GetString(0));
item.Add(WorkflowServiceNamespace.RelativeApplicationPath, reader.GetString(1));
item.Add(WorkflowServiceNamespace.RelativeServicePath, reader.GetString(2));
parameters.Add(item);
}
while (reader.Read());
}
else
{
base.Store.UpdateEventStatus(false, InstancePersistenceEvent<HasActivatableWorkflowEvent>.Value);
base.StoreLock.InstanceDetectionTask.ResetTimer(false);
}
base.InstancePersistenceContext.QueriedInstanceStore(new ActivatableWorkflowsQueryResult(parameters));
}
return nextResultSet;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:28,代码来源:QueryActivatableWorkflowAsyncResult.cs
示例6: BuildClientOrder
public static YellowstonePathology.Business.ClientOrder.Model.ClientOrder BuildClientOrder(SqlDataReader dr)
{
YellowstonePathology.Business.ClientOrder.Model.ClientOrder clientOrder = null;
Nullable<int> panelSetId = null;
while (dr.Read())
{
if (dr["PanelSetId"] != DBNull.Value)
{
panelSetId = Convert.ToInt32(dr["PanelSetId"].ToString());
}
}
clientOrder = YellowstonePathology.Business.ClientOrder.Model.ClientOrderFactory.GetClientOrder(panelSetId);
dr.NextResult();
while (dr.Read())
{
YellowstonePathology.Business.Persistence.SqlDataReaderPropertyWriter propertyWriter = new Persistence.SqlDataReaderPropertyWriter(clientOrder, dr);
propertyWriter.WriteProperties();
}
dr.NextResult();
while (dr.Read())
{
YellowstonePathology.Business.Client.Model.ClientLocation clientLocation = new YellowstonePathology.Business.Client.Model.ClientLocation();
YellowstonePathology.Business.Persistence.SqlDataReaderPropertyWriter propertyWriter = new YellowstonePathology.Business.Persistence.SqlDataReaderPropertyWriter(clientLocation, dr);
propertyWriter.WriteProperties();
clientOrder.ClientLocation = clientLocation;
}
return clientOrder;
}
示例7: Convert
public static void Convert(ShapefileGeometryType type, SqlDataReader reader, string shapefile)
{
if (!reader.Read())
throw new Exception("No Results found");
int geomOrdinal, colCount;
ShapefileHeader shapeHeader = ShapefileHeader.CreateEmpty(type);
DbfHeader dbfHeader = BuildHeader(reader, out geomOrdinal, out colCount);
GeometryFactory factory = new GeometryFactory();
Envelope env = shapeHeader.Bounds;
using (ShapefileDataWriter writer = ShapefileDataWriter.Create(shapefile, dbfHeader, shapeHeader))
{
do
{
SqlGeometry geom = reader[geomOrdinal] as SqlGeometry;
if (!geom.STIsValid())
geom = geom.MakeValid();
for (int i = 0, offset = 0; i < colCount; i++)
{
if (i == geomOrdinal)
offset++;
writer.Record.SetRaw(i, reader[i + offset]);
}
ExpandEnv(env, geom.STBoundary());
writer.Write(ConvertToGeometry.SqlGeometryToGeometry(geom, factory));
}
while (reader.Read());
}
}
示例8: CreatePostsFromReader
public static Collection<Post> CreatePostsFromReader(SqlDataReader reader)
{
// First result set is the postcategories.
Dictionary<int, Category> postcats = new Dictionary<int, Category>();
if (reader.HasRows)
{
while (reader.Read())
{
// Oops - key can't be PostId as key has to be unique. Need to use a different collection..
// .. for now, make a hash of the post and category IDs.
int categoryId = Convert.ToInt32(reader["categoryId"]);
int postHash = (Convert.ToInt32(reader["PostId"]) * 10000) + categoryId;
postcats.Add(postHash, new Category(categoryId, Convert.ToString(reader["Name"]), Convert.ToString(reader["Slug"])));
}
}
// Second resultset is the post(s)
reader.NextResult();
Collection<Post> postlist = new Collection<Post>();
if (reader.HasRows)
{
while (reader.Read())
{
Post p = new Post();
p.Id = Convert.ToInt32(reader["Id"]);
p.Title = Convert.ToString(reader["Title"]);
p.Postdate = Convert.ToDateTime(reader["PostDate"]);
p.Body = Convert.ToString(reader["Body"]);
p.Slug = Convert.ToString(reader["Slug"]);
p.CommentCount = Convert.ToInt32(reader["CommentCount"]);
p.Published = Convert.ToBoolean(reader["Published"]);
p.Categories = new Collection<Category>();
// .. then the categories.
IEnumerable<Category> cats =
from entry in postcats
where ((entry.Key / 10000) == p.Id)
select entry.Value;
foreach (Category cat in cats)
{
p.Categories.Add(cat);
}
postlist.Add(p);
}
}
return postlist;
}
示例9: RoadMap
public RoadMap(string name )
{
mName = name;
mDatabase.connect();
mReader = mDatabase.executeread("SELECT Timestamp, Description, UserID FROM [dbo].[Roadmap] WHERE Name = '" + name + "'");
mReader.Read();
mTimeStamp = mReader.GetDateTime(0);
mDescription = mReader.GetString(1);
string UID = mReader.GetString(2);
mDatabase.close();
mDatabase.connect();
mReader = mDatabase.executeread("SELECT Name, Email, Password FROM [dbo].[User] WHERE ID = '" + UID + "'");
mReader.Read();
mUser = new User(mReader.GetString(0), UID, mReader.GetString(1), mReader.GetString(2));
mDatabase.close();
mTimeline = new TimeLine(mName);
//Get the StrategyPoints
mDatabase.connect();
mReader = mDatabase.executeread("SELECT Name, Description FROM [dbo].[StrategyPoint] WHERE RoadmapName = '" + name + "'");
while (mReader.Read())
{
StrategyPoint sp = new StrategyPoint(mReader.GetString(0), mReader.GetString(1));
mStrategyPoints.Add(sp);
}
mDatabase.close();
}
示例10: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
con = new SqlConnection(ConfigurationManager.ConnectionStrings["devi"].ToString());
con.Open();
cmd = new SqlCommand("select * from user1_reg where lid='" + Session["usr"].ToString() + "'");
cmd.Connection = con;
dr = cmd.ExecuteReader();
if (dr.Read())
{
Label1.Text = "<img src='userfig/"+dr[11].ToString()+"' width='100' height='150' /><br />Welcome " + dr[1].ToString();
}
con.Close();
con.Open();
string fid = Request.QueryString["fid"].ToString();
cmd = new SqlCommand("select * from cloud_data where id='"+fid+"'");
cmd.Connection = con;
dr = cmd.ExecuteReader();
if (dr.Read())
{
Label3.Text = dr[2].ToString();
TextBox3.Text = dr[3].ToString();
TextBox4.Text = dr[5].ToString();
TextBox5.Text = dr[7].ToString();
TextBox6.Text = dr[9].ToString();
}
con.Close();
}
示例11: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
string idtiket = Request.QueryString["tiketid"];
userconnection = new SqlConnection();
userconnection.ConnectionString = @"Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aviation.mdf;Trusted_Connection=True;User Instance=True";
usercommand = new SqlCommand();
usercommand.Connection = userconnection;
usercommand.CommandText = "SELECT * FROM application WHERE [email protected]";
usercommand.Parameters.Clear();
usercommand.Parameters.AddWithValue("@id", idtiket);
try
{
userconnection.Open();
userreader = usercommand.ExecuteReader();
if (userreader.Read())
{
Response.ContentType = userreader["MIME"].ToString();
Response.BinaryWrite((byte[])userreader["BinaryData"]);
}
}
catch (SqlException ex)
{
}
finally
{
userconnection.Close();
}
}
示例12: sendEachRecordOfData
private static void sendEachRecordOfData(SqlDataReader dataReader, SqlMetaData[] meta)
{
while (dataReader.Read())
{
SqlContext.Pipe.SendResultsRow(createRecordPopulatedWithData(dataReader, meta));
}
}
示例13: GetColoumns
public List<Columns> GetColoumns(string tableName,string dbName)
{
List<Columns> allColoumns = new List<Columns>();
string database = "USE " + dbName;
try
{
GetSqlConn.Open();
commandString = string.Format(database+" select COLUMN_NAME,DATA_TYPE from information_schema.columns where table_name = @tableName");
GetSqlCommand.CommandText = commandString;
GetSqlCommand.Parameters.Clear();
GetSqlCommand.Parameters.Add("@tableName", SqlDbType.NVarChar);
GetSqlCommand.Parameters["@tableName"].Value = tableName;
getData = GetSqlCommand.ExecuteReader();
while (getData.Read())
{
Columns aColoumn = new Columns();
aColoumn.ColName = getData["COLUMN_NAME"].ToString();
aColoumn.DataType = getData["DATA_TYPE"].ToString();
allColoumns.Add(aColoumn);
}
}
catch (Exception exp)
{
throw new Exception("Error while fetching data" + exp);
}
finally
{
GetSqlConn.Close();
}
return allColoumns;
}
示例14: CheckSalesPersonLogIn
// CHECK IF SALES PERSON EXIST IN DATBASE
public static string CheckSalesPersonLogIn(SqlDataReader dr)
{
bool noExist = true;
bool isActive = true;
string clear = null;
while (dr.Read())
{
clear = dr.GetString(0);
isActive = dr.GetBoolean(5);
noExist = false;
}
if (!isActive)
{
MessageBox.Show("Sorry, you are fired!", "LOL", MessageBoxButtons.OK, MessageBoxIcon.Error);
return null;
}
else if (noExist)
{
MessageBox.Show("Not in the register.", "Unregistered Sales Person", MessageBoxButtons.OK, MessageBoxIcon.Error);
return null;
}
else
{
return clear;
}
}
示例15: clienteRegistrado
public int clienteRegistrado( string Tipo_ID, int Numero_ID)
{
con1.cnn.Open();
int contador = 0;
try
{
string query = "SELECT id_tipo_doc, num_doc FROM LPP.CLIENTES WHERE id_tipo_doc = (SELECT tipo_cod FROM LPP.TIPO_DOCS WHERE tipo_descr = '" + Tipo_ID + "') AND num_doc = " + Numero_ID + "";
SqlCommand command = new SqlCommand(query, con1.cnn);
dr = command.ExecuteReader();
while (dr.Read())
{
contador++;
}
dr.Close();
}
catch (Exception )
{
con1.cnn.Close();
return contador;
}
con1.cnn.Close();
//MessageBox.Show("El Cliente ya existe");
return 0;
}