473,320 Members | 2,092 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

SQLDataReader and the length of a string field

Dom
I use SQLDataReader to obtain data from a SQL Server backend. Within
the program, I need to know the length of some of the varchar fields.
Not the length of the returned value, but the maximum length, as it is
specified in the database.

How do I do this? I'm expecting something like this:

SQLDataReader r = (...)
r.GetDataLength (i)

.... but I can't find it.

Dom
Apr 1 '08 #1
3 5357
Since you didn't say what this is for I'm going to make a guess and
say that you want to dynamically create fields and limit them by the
maxlength, or something similar to that. The only way I know to do
this is to query the system tables which contains all that
information. In my own code I was going to create an object that I
could use to query the system tables in certain ways to get this
information and similar information.
Apr 1 '08 #2
Dom
On Apr 1, 4:23*pm, "cfps.Christian" <ge0193...@otc.eduwrote:
Since you didn't say what this is for I'm going to make a guess and
say that you want to dynamically create fields and limit them by the
maxlength, or something similar to that. *The only way I know to do
this is to query the system tables which contains all that
information. *In my own code I was going to create an object that I
could use to query the system tables in certain ways to get this
information and similar information.
My reason for asking is this: My program allows the user to change
these fields, so I have to make sure that, if the field is varchar
(50), and he enters 51 characters, the program gives him a warning.

I take your point, though. I believe that in the days of ADO, you got
this from the RecordSet object.

Apr 1 '08 #3
Dom wrote:
I use SQLDataReader to obtain data from a SQL Server backend. Within
the program, I need to know the length of some of the varchar fields.
Not the length of the returned value, but the maximum length, as it is
specified in the database.
I don't think you can get that info from your current DataReader.

But:

SELECT COLUMN_NAME,CHARACTER_MAXIMUM_LENGTH FROM
INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA=@tblnam

should get it.

Arne
Apr 2 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: smeagol | last post by:
I have a varchar 255 field in the Sql. When i get the data with (string)myReader; it's trimed ie( SQL : "qwerty " (Lenght 255) c# :...
2
by: Matt | last post by:
I just want to get the value of field UserName and Password in SqlDataReader object dr. But it yeields run-time error "Invalid attempt to read when no data is present" on line dr("UserName") and...
4
by: mimi | last post by:
Hi Please help me out, I can't find a way to close a sqldatareader when error occur at statement cmd.ExecuteReader(). I can't close it in catch because it is local in try scope and I can't...
5
by: Woody Splawn | last post by:
I have some code that looks like this: Dim SSN, LName, FName, M As String mySqlConnection = New SqlConnection(myConnectionString) Dim sql_Command As New SqlCommand( _ "Select SSN, LName, FName,...
7
by: Rich | last post by:
Is there any builtin functionality to the SqlDataReader for getting a row count of records retrieved? Rather than Do While rdr.Read: i+=1: Loop?
7
by: Web learner | last post by:
I am trying to create a method GetDataFor(string column) becaues I have to repeat the same statements for several columns but I get an error as follows: The name 'dr' does not exist in the current...
3
by: dchristjohn | last post by:
I am currently developing a small windows application using Visual Basic via Visual Studio 2005. My database resides on a SQL 2000 server. I have a table with three fields: id (int, Not Null)...
3
by: Dom | last post by:
Still teaching myself about SQLDataReader and associated classes. I have to say, the new HELP screens from MS are just about useless!! Let's assume I have just read some records from a table...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.