473,800 Members | 2,383 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5383
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,CHA RACTER_MAXIMUM_ LENGTH FROM
INFORMATION_SCH EMA.COLUMNS WHERE TABLE_SCHEMA=@t blnam

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
1881
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# : (string)myReader.Lenght; (=5) It's possible to get (string)myReader.Lenght; (=255)
2
1629
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 dr("Password") any ideas?? Dim sql As String = "select * from where UserName = '" & TextBox1.Text & "'" _ & "AND Password = '" & TextBox2.Text & "'" & ";" Dim cmd As New SqlCommand(sql, cn)
4
2366
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 declare it outside try scope either since we have to call cmd.executeReader to create sqldatareader public string GetLogs(int logID) {
5
6597
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, M from Students WHERE (SSN = " + " '" + ProposedValue + "')", _ mySqlConnection) Try mySqlConnection.Open()
7
29866
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
1715
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 context It seems the dr -the instance of sqlDataReader - is not becoming available to the method. How to make it available? This seems trivial and newbie problem related to OOP, but I am confused. Could you pl. look at the code or point me to...
3
3270
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) lname (varchar(30), Not Null) fname (varchar(30), Not Null) I have one record in the table as follows:
3
1851
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 into the SQLDataReader object, r. 1. Am I right to assume that accessing the fields as r is a little faster than r? 2. The elements of r are all objects. I can changes these to the
0
9691
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10505
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10253
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10035
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7580
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.