sqldatareader

Datareader Retrieving Data

為{幸葍}努か 提交于 2020-01-30 11:32:34
问题 I have Memberships and Bookings tables in a database containing an attribute cust_id, which is the primary key in Memberships and reference key in Bookings. When I am executing a data reader I want it to read cust_id values from membership table but it is reading it from the bookings table. Also, when I compare two cust_id values, 1 taken from a textbox and the other taken a from database column, even though both are the same, but the comparison result is false. I have compared using string

The type 'System.Data.SqlClient.SqlDataReader' has no constructors defined

感情迁移 提交于 2020-01-24 22:24:50
问题 I have issues with SqlDataReader. I get the error "The type 'System.Data.SqlClient.SqlDataReader' has no constructors defined" when I try running the page. My intention here is to return a string value 0 if the user has not had access or 1 when the user has assess. Below is my code snippet. public string CheckAssess(string emailAddress, string columnName) { string chkAssess; SqlDataReader readAssess; readAssess = new SqlDataReader(); string MgrAssessQry = "SELECT '"+columnName+"' FROM

The type 'System.Data.SqlClient.SqlDataReader' has no constructors defined

↘锁芯ラ 提交于 2020-01-24 22:24:28
问题 I have issues with SqlDataReader. I get the error "The type 'System.Data.SqlClient.SqlDataReader' has no constructors defined" when I try running the page. My intention here is to return a string value 0 if the user has not had access or 1 when the user has assess. Below is my code snippet. public string CheckAssess(string emailAddress, string columnName) { string chkAssess; SqlDataReader readAssess; readAssess = new SqlDataReader(); string MgrAssessQry = "SELECT '"+columnName+"' FROM

System.IndexOutOfRangeException on SQLDataReader Value Using C#

烂漫一生 提交于 2020-01-24 10:03:35
问题 I have a SQLDataReader that returns three integers. However, there are occasions when two of the integers will return null values. To get round this I wrote the following: int shoppingCartHeadID = 0; int billID = 0; int delID = 0; conn.Open(); reader = comm.ExecuteReader(); if (reader.Read()) { shoppingCartHeadID = Convert.ToInt32(reader["shoppingCartHeadID"]); if (!reader.IsDBNull(billID)) { billID = Convert.ToInt32(reader["billID"]); } if (!reader.IsDBNull(delID)) { delID = Convert.ToInt32

Putting data from SqlDataReader into HTML table

戏子无情 提交于 2020-01-15 08:55:08
问题 I have some data in a database that I read out with SqlDataReader . I want to put these in a HTML table in my ASP.NET site, but I can't figure out how to do so. 回答1: You can use a gridview. It is an asp.net control which you just bind your datareader to your gridview, and it will display every row that is returned from your database as an html table row. You can even combine two or more columns, and add pictures or links instead of just displaying the data with a templated row. Google it and

Retrieve Datareader using Objects

青春壹個敷衍的年華 提交于 2020-01-14 05:35:10
问题 I have worked on retrieving the data from SQL database using Datareader and populate it in Datatable.. But, I am wondering whether is there any way to handle the data from datareader without using datatable ? I mean- handling the table values using Objects should be more preferable.. But, I dont want to use LINQ here since, I am going to use ADOMD object to pull the data from database(Cubes).. 回答1: Have a look at dapper-dot-net. I'm not sure how it works with ADOMD.NET, but it does neatly

Convert C# 2.0 System.Data.SqlTypes.SqlXml object into a System.Xml.XmlNode

让人想犯罪 __ 提交于 2020-01-13 19:26:27
问题 I seem to always have problems with converting data to and from XML in C#. It always wants you to create a full XMLDocument object even when you think you shouldn't have to. In this case I have a SQLXML column in a MS SQL 2005 server that I am trying to pull out and push into a function that requires an XMLNode as a parameter. You would think this would be easy, but outside of converting it to a string and creating a new XMLNode object I cannot figure out the right way to do it. I can use an

Check if it's the last record in sqldatareader

半世苍凉 提交于 2020-01-12 14:01:21
问题 Is there a way to check if I'm on the last record ? thanks 回答1: Use this pattern to identify and process the last row in result: if (reader.Read()) { var loop = true; while (loop) { //1. Here retrive values you need e.g. var myvar = reader.GetBoolean(0); loop = reader.Read(); if (!loop) { //You are on the last record. Use values read in 1. //Do some exceptions } else { //You are not on the last record. //Process values read in 1., e.g. myvar } } } 回答2: Other than "there isn't another one

How to get the exact type of numeric columns incl. scale and precision?

孤街浪徒 提交于 2020-01-12 07:50:11
问题 Is there a way to know the exact type of a column in a DataTable ? Right now I am doing this: DataTable st = dataReader.GetSchemaTable(); foreach (DataColumn col in st.Columns) { var type = col.DataType; } Now with type.Name I am able to find if it is a number( int or decimal ..) or string but the problem is that I need the exact type, for example if in database let say column Rate is NUMBER(4,3) then here in my code I am only getting type as 'Decimal' and no information about the Format 4,3

MAX(id) using SqlDataReader C#

狂风中的少年 提交于 2020-01-10 03:14:07
问题 How do I change this: using (SqlCommand myCommand = myConnection.CreateCommand()) { myConnection.Open(); myCommand.CommandText = "SELECT FormID FROM tbl_Form"; using (SqlDataReader reader = myCommand.ExecuteReader()) { while (reader.Read()) { int FormID = reader.GetInt32(reader.GetOrdinal("FormID")); MessageBox.Show(FormID.ToString()); } } } to get MAX(FormID) ? My natural tendency is to throw a MAX around FormID but I'm getting an IndexOutOfRange exception. 回答1: When you select the maximum