datareader

C# How can I get each column type and length and then use the lenght to padright to get the spaces at the end of each field

非 Y 不嫁゛ 提交于 2019-12-23 12:19:18
问题 I have a console application that extracts data from a SQL table to a flat file. How can I get each column type and length and then use the lenght of each column to padright(length) to get the spaces at the end of each field. Here is what I have right now that does not include this functionality. Thanks { var destination = args[0]; var command = string.Format("Select * from {0}", Validator.Check(args[1])); var connectionstring = string.Format("Data Source={0}; Initial Catalog=dbname

Access a specific row in DataReader

醉酒当歌 提交于 2019-12-23 10:49:35
问题 I have a datareader to display a list of gameweeks in a js carousel. I need to be able to add an if statement to change the div class of the current gameweek. This is my current code: if (dReader.HasRows) { while (dReader.Read()) { gameweekList.Text += "<div class=\"item\"><h4>Gameweek " + (dReader["gameweekID"].ToString()) + "</h4></div>"; } } else { gameweekList.Text = "Error Finding Gameweeks"; } dReader.Close(); conn.Close(); In effect I want to add if(dreader[1]) then add the extra bit,

How to easily convert a DbDataReader object into something useful?

对着背影说爱祢 提交于 2019-12-23 04:53:36
问题 I am manually calling a stored procedure using an Entity Framework EntityConnection like so: DbConnection storeConnection = entityConnection.StoreConnection; DbCommand command = storeConnection.CreateCommand(); command.CommandText = "sp_GetMyComplexData"; command.CommandType = CommandType.StoredProcedure; DbDataReader reader = command.ExecuteReader(); The reason for this is that the entity framework doesn't easily support entities that don't directly map to tables or views. I found this

Invalid attempt to read when no data is present in dr

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-22 10:09:17
问题 I am trying to create a login form on my ASP.NET website. Currently, there's some problem. I am trying to incorporate the functionality such that the logged in user has the previlige to view only his profile. The code on the login page is this: business.clsprofiles obj = new business.clsprofiles(); Int32 a = obj.logincheck(TextBox3.Text, TextBox4.Text); if (a == -1) { Label1.Text = "Username/Password incorrect"; } else { Session["cod"]= a; Response.Redirect("profile.aspx"); } After logging in

convert dataReader to Dictionary

时间秒杀一切 提交于 2019-12-22 07:37:23
问题 I tried to use LINQ to convert one row to Dictionary (fieldName -> fieldValue) return Enumerable.Range(0, reader.FieldCount) .ToDictionary<string, object>(reader.GetName, reader.GetValue); but I received error message: Instance argument: cannot convert from 'System.Collections.Generic.IEnumerable<int>' to 'System.Collections.Generic.IEnumerable<string>' How to correct this? 回答1: return Enumerable.Range(0, reader.FieldCount) .ToDictionary( i => reader.GetName(i), i => reader.GetValue(i)); 来源:

What is the best way to load huge result set in memory?

对着背影说爱祢 提交于 2019-12-22 05:50:09
问题 I am trying to load 2 huge resultsets(source and target) coming from different RDBMS but the problem with which i am struggling is getting those 2 huge result set in memory. Considering below are the queries to pull data from source and target: Sql Server - select Id as LinkedColumn,CompareColumn from Source order by LinkedColumn Oracle - select Id as LinkedColumn,CompareColumn from Target order by LinkedColumn Records in Source : 12377200 Records in Target : 12266800 Following are the

Pause URL request Downloads

谁说胖子不能爱 提交于 2019-12-22 00:27:55
问题 import urllib.request import re import csv import pandas as pd from bs4 import BeautifulSoup columns = [] data = [] f = open('companylist.csv') csv_f = csv.reader(f) for row in csv_f: stocklist = row print(stocklist) for s in stocklist: print('http://finance.yahoo.com/q?s='+s) optionsUrl = urllib.request.urlopen('http://finance.yahoo.com/q?s='+s).read() soup = BeautifulSoup(optionsUrl, "html.parser") stocksymbol = ['Symbol:', s] optionsTable = [stocksymbol]+[ [x.text for x in y.parent

Can I create an anonymous type collection from a DataReader?

假如想象 提交于 2019-12-21 00:42:00
问题 I have this code: var query = "SELECT * FROM Cats"; var conn = new SqlConnection(sqlConnectionString); conn.Open(); var cmd = new SqlCommand(query); var reader = cmd.ExecuteReader(); while (reader.Read()) { var CatName = reader.GetString(0); var CatDOB = reader.GetDateTime(1); var CatStatus = reader.GetInt32(2); } I'd like to pull the rows out into an anonymous type collection, which I'd normally do using LINQ to iterate, but I an not sure if it's possible due to the way you have to call

Bind datagrid to datareader

陌路散爱 提交于 2019-12-20 03:16:54
问题 I want to be able to enter SQL into a textbox and display the results in a WPF Datagrid. I thought to start with an SqlDataReader , and set the datagrid's ItemsSource to the data reader: using (var cmd = conn.CreateCommand()) { cmd.CommandText = sql.Text; sqlResults.ItemsSource = cmd.ExecuteReader(); } but this fails with the following error: Invalid attempt to call FieldCount when reader is closed , which I understand to mean that by the time WPF gets around to reading the FieldCount

DataReader - hardcode ordinals?

家住魔仙堡 提交于 2019-12-19 05:10:13
问题 When returning data from a DataReader I would typically use the ordinal reference on the DataReader to grab the relevant column: if (dr.HasRows) Console.WriteLine(dr[0].ToString()); or if (dr.HasRows) Console.WriteLine(dr.GetString(0)); or if (dr.HasRows) Console.WriteLine((string)dr[0]); I have always done this because I was advised at an early stage that using dr["ColumnName"] or a more elegant way of indexing causes a performance hit. However, while all references to data entities are