473,396 Members | 1,853 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,396 software developers and data experts.

Pass / Store data type

I am trying to write a class that will store info about database fields for
building UPDATE / INSERT commands later on. I cannot seem to get the sytax
correct to pass and store the data type of the field. My class looks like:

Public Class DataTag
Private m_Text As String
Private m_FieldName As String
Private m_ParamName As String
Private m_DataType As System.Type 'the variable type of this field

Public Sub New(ByVal sText As String, ByVal sField As String, ByVal sParam
As String, ByVal typeData As System.Type)
m_Text = sText
m_FieldName = sField
m_ParamName = sParam
m_DataType = typeData
End Sub

When I try to define an object with:

txtName.Tag = New DataTag(txtName.Text, "Name", "@Name", System.String)

System.String shows error: 'String' is a type in 'System' and cannot be used
in an expression. I have also tried using a GetType property on a string,
but that has failed also. How can I pass and store the data type of the
field? I want to do this so that I can later loop through the text boxes
and do something like...

MySQLCommand.Parameters.Add(dataTagCurrent.paramNa me,
dataTagCurrent.DataType).Value = txtLoop.Text

Or something similar based on the control/data type, and also build the SQL
Command string.

Any help appreciated - thanks,
Mike
Nov 21 '05 #1
6 2019
Is this not working for you?

txtName.Tag = New DataTag(txtName.Text, "Name", _
"@Name", GetType(System.String))

Imran.

"Mike Hoff" <mi**@home.com> wrote in message
news:10*************@corp.supernews.com...
I am trying to write a class that will store info about database fields for building UPDATE / INSERT commands later on. I cannot seem to get the sytax correct to pass and store the data type of the field. My class looks like:
Public Class DataTag
Private m_Text As String
Private m_FieldName As String
Private m_ParamName As String
Private m_DataType As System.Type 'the variable type of this field

Public Sub New(ByVal sText As String, ByVal sField As String, ByVal sParam
As String, ByVal typeData As System.Type)
m_Text = sText
m_FieldName = sField
m_ParamName = sParam
m_DataType = typeData
End Sub

When I try to define an object with:

txtName.Tag = New DataTag(txtName.Text, "Name", "@Name", System.String)

System.String shows error: 'String' is a type in 'System' and cannot be used in an expression. I have also tried using a GetType property on a string,
but that has failed also. How can I pass and store the data type of the
field? I want to do this so that I can later loop through the text boxes
and do something like...

MySQLCommand.Parameters.Add(dataTagCurrent.paramNa me,
dataTagCurrent.DataType).Value = txtLoop.Text

Or something similar based on the control/data type, and also build the SQL Command string.

Any help appreciated - thanks,
Mike

Nov 21 '05 #2
Hi Mike,

Instead of Private m_DataType As System.Type

Try: Private m_DataType as Integer

Then when you pass to the function use SqlDbType.VarChar or whatever type it
is you are using. SqlDbType is just a class that holds Constants. Remember
to import System.Data.SqlClient wherever you use it. Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight

"Mike Hoff" <mi**@home.com> wrote in message
news:10*************@corp.supernews.com...
I am trying to write a class that will store info about database fields for building UPDATE / INSERT commands later on. I cannot seem to get the sytax correct to pass and store the data type of the field. My class looks like:
Public Class DataTag
Private m_Text As String
Private m_FieldName As String
Private m_ParamName As String
Private m_DataType As System.Type 'the variable type of this field

Public Sub New(ByVal sText As String, ByVal sField As String, ByVal sParam
As String, ByVal typeData As System.Type)
m_Text = sText
m_FieldName = sField
m_ParamName = sParam
m_DataType = typeData
End Sub

When I try to define an object with:

txtName.Tag = New DataTag(txtName.Text, "Name", "@Name", System.String)

System.String shows error: 'String' is a type in 'System' and cannot be used in an expression. I have also tried using a GetType property on a string,
but that has failed also. How can I pass and store the data type of the
field? I want to do this so that I can later loop through the text boxes
and do something like...

MySQLCommand.Parameters.Add(dataTagCurrent.paramNa me,
dataTagCurrent.DataType).Value = txtLoop.Text

Or something similar based on the control/data type, and also build the SQL Command string.

Any help appreciated - thanks,
Mike

Nov 21 '05 #3
Thanks for responses - using Integer worked like a charm.
"Ken Dopierala Jr." <kd*********@wi.rr.com> wrote in message
news:uv****************@TK2MSFTNGP09.phx.gbl...
Hi Mike,

Instead of Private m_DataType As System.Type

Try: Private m_DataType as Integer

Then when you pass to the function use SqlDbType.VarChar or whatever type it is you are using. SqlDbType is just a class that holds Constants. Remember to import System.Data.SqlClient wherever you use it. Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight

"Mike Hoff" <mi**@home.com> wrote in message
news:10*************@corp.supernews.com...
I am trying to write a class that will store info about database fields

for
building UPDATE / INSERT commands later on. I cannot seem to get the

sytax
correct to pass and store the data type of the field. My class looks

like:

Public Class DataTag
Private m_Text As String
Private m_FieldName As String
Private m_ParamName As String
Private m_DataType As System.Type 'the variable type of this field
Public Sub New(ByVal sText As String, ByVal sField As String, ByVal sParam As String, ByVal typeData As System.Type)
m_Text = sText
m_FieldName = sField
m_ParamName = sParam
m_DataType = typeData
End Sub

When I try to define an object with:

txtName.Tag = New DataTag(txtName.Text, "Name", "@Name", System.String)

System.String shows error: 'String' is a type in 'System' and cannot be

used
in an expression. I have also tried using a GetType property on a string, but that has failed also. How can I pass and store the data type of the
field? I want to do this so that I can later loop through the text boxes and do something like...

MySQLCommand.Parameters.Add(dataTagCurrent.paramNa me,
dataTagCurrent.DataType).Value = txtLoop.Text

Or something similar based on the control/data type, and also build the

SQL
Command string.

Any help appreciated - thanks,
Mike


Nov 21 '05 #4
Hi Mike and Ken,

I had a similar question and was hoping that either of you could help me. It
is probably a dumb queston but I was trying to determine the type of column
coming back from a resultset to format a date but I don't know what to
compare it to for the type.

I was hoping to do this

If MySqlDataReader.GetFieldType(0) = <DATETIME constant>

trying SqlDbType types and GetType() on the RHS with no luck.

Thanks for your time
Regards
Amelia

"Mike Hoff" wrote:
Thanks for responses - using Integer worked like a charm.
"Ken Dopierala Jr." <kd*********@wi.rr.com> wrote in message
news:uv****************@TK2MSFTNGP09.phx.gbl...
Hi Mike,

Instead of Private m_DataType As System.Type

Try: Private m_DataType as Integer

Then when you pass to the function use SqlDbType.VarChar or whatever type

it
is you are using. SqlDbType is just a class that holds Constants.

Remember
to import System.Data.SqlClient wherever you use it. Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight

"Mike Hoff" <mi**@home.com> wrote in message
news:10*************@corp.supernews.com...
I am trying to write a class that will store info about database fields

for
building UPDATE / INSERT commands later on. I cannot seem to get the

sytax
correct to pass and store the data type of the field. My class looks

like:

Public Class DataTag
Private m_Text As String
Private m_FieldName As String
Private m_ParamName As String
Private m_DataType As System.Type 'the variable type of this field
Public Sub New(ByVal sText As String, ByVal sField As String, ByVal sParam As String, ByVal typeData As System.Type)
m_Text = sText
m_FieldName = sField
m_ParamName = sParam
m_DataType = typeData
End Sub

When I try to define an object with:

txtName.Tag = New DataTag(txtName.Text, "Name", "@Name", System.String)

System.String shows error: 'String' is a type in 'System' and cannot be

used
in an expression. I have also tried using a GetType property on a string, but that has failed also. How can I pass and store the data type of the
field? I want to do this so that I can later loop through the text boxes and do something like...

MySQLCommand.Parameters.Add(dataTagCurrent.paramNa me,
dataTagCurrent.DataType).Value = txtLoop.Text

Or something similar based on the control/data type, and also build the

SQL
Command string.

Any help appreciated - thanks,
Mike



Nov 21 '05 #5
Hi Amelia,

There are a couple ways you can do this. The first is instead of using
GetFieldType() use:

MySqlDataReader.GetDataTypeName(0)

This will return a string of the data type the field contains. For example
and Integer = 'int'. Another way to test for a date is to test against the
actual field:

If (IsDate(MySqlDataReader("DateField")) Then
....process as date
End If

Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight

"Amelia" <Am****@discussions.microsoft.com> wrote in message
news:A8**********************************@microsof t.com...
Hi Mike and Ken,

I had a similar question and was hoping that either of you could help me. It is probably a dumb queston but I was trying to determine the type of column coming back from a resultset to format a date but I don't know what to
compare it to for the type.

I was hoping to do this

If MySqlDataReader.GetFieldType(0) = <DATETIME constant>

trying SqlDbType types and GetType() on the RHS with no luck.

Thanks for your time
Regards
Amelia

"Mike Hoff" wrote:
Thanks for responses - using Integer worked like a charm.
"Ken Dopierala Jr." <kd*********@wi.rr.com> wrote in message
news:uv****************@TK2MSFTNGP09.phx.gbl...
Hi Mike,

Instead of Private m_DataType As System.Type

Try: Private m_DataType as Integer

Then when you pass to the function use SqlDbType.VarChar or whatever type
it
is you are using. SqlDbType is just a class that holds Constants.

Remember
to import System.Data.SqlClient wherever you use it. Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight

"Mike Hoff" <mi**@home.com> wrote in message
news:10*************@corp.supernews.com...
> I am trying to write a class that will store info about database

fields for
> building UPDATE / INSERT commands later on. I cannot seem to get the sytax
> correct to pass and store the data type of the field. My class looks like:
>
> Public Class DataTag
> Private m_Text As String
> Private m_FieldName As String
> Private m_ParamName As String
> Private m_DataType As System.Type 'the variable type of this

field
>
> Public Sub New(ByVal sText As String, ByVal sField As String, ByVal

sParam
> As String, ByVal typeData As System.Type)
> m_Text = sText
> m_FieldName = sField
> m_ParamName = sParam
> m_DataType = typeData
> End Sub
>
> When I try to define an object with:
>
> txtName.Tag = New DataTag(txtName.Text, "Name", "@Name", System.String) >
> System.String shows error: 'String' is a type in 'System' and cannot be used
> in an expression. I have also tried using a GetType property on a

string,
> but that has failed also. How can I pass and store the data type of the > field? I want to do this so that I can later loop through the text

boxes
> and do something like...
>
> MySQLCommand.Parameters.Add(dataTagCurrent.paramNa me,
> dataTagCurrent.DataType).Value = txtLoop.Text
>
> Or something similar based on the control/data type, and also build the SQL
> Command string.
>
> Any help appreciated - thanks,
> Mike
>
>


Nov 21 '05 #6
Hi Ken,

Thanks so much for your help and time - it really saved my bacon! Still
trying to work my way around .Net but determined to know all the classes soon
AND how to use them!

:0)

Amelia

"Ken Dopierala Jr." wrote:
Hi Amelia,

There are a couple ways you can do this. The first is instead of using
GetFieldType() use:

MySqlDataReader.GetDataTypeName(0)

This will return a string of the data type the field contains. For example
and Integer = 'int'. Another way to test for a date is to test against the
actual field:

If (IsDate(MySqlDataReader("DateField")) Then
....process as date
End If

Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight

"Amelia" <Am****@discussions.microsoft.com> wrote in message
news:A8**********************************@microsof t.com...
Hi Mike and Ken,

I had a similar question and was hoping that either of you could help me.

It
is probably a dumb queston but I was trying to determine the type of

column
coming back from a resultset to format a date but I don't know what to
compare it to for the type.

I was hoping to do this

If MySqlDataReader.GetFieldType(0) = <DATETIME constant>

trying SqlDbType types and GetType() on the RHS with no luck.

Thanks for your time
Regards
Amelia

"Mike Hoff" wrote:
Thanks for responses - using Integer worked like a charm.
"Ken Dopierala Jr." <kd*********@wi.rr.com> wrote in message
news:uv****************@TK2MSFTNGP09.phx.gbl...
> Hi Mike,
>
> Instead of Private m_DataType As System.Type
>
> Try: Private m_DataType as Integer
>
> Then when you pass to the function use SqlDbType.VarChar or whatever type it
> is you are using. SqlDbType is just a class that holds Constants.
Remember
> to import System.Data.SqlClient wherever you use it. Good luck! Ken.
>
> --
> Ken Dopierala Jr.
> For great ASP.Net web hosting try:
> http://www.webhost4life.com/default.asp?refid=Spinlight
>
> "Mike Hoff" <mi**@home.com> wrote in message
> news:10*************@corp.supernews.com...
> > I am trying to write a class that will store info about database fields > for
> > building UPDATE / INSERT commands later on. I cannot seem to get the > sytax
> > correct to pass and store the data type of the field. My class looks > like:
> >
> > Public Class DataTag
> > Private m_Text As String
> > Private m_FieldName As String
> > Private m_ParamName As String
> > Private m_DataType As System.Type 'the variable type of this
field
> >
> > Public Sub New(ByVal sText As String, ByVal sField As String, ByVal
sParam
> > As String, ByVal typeData As System.Type)
> > m_Text = sText
> > m_FieldName = sField
> > m_ParamName = sParam
> > m_DataType = typeData
> > End Sub
> >
> > When I try to define an object with:
> >
> > txtName.Tag = New DataTag(txtName.Text, "Name", "@Name", System.String) > >
> > System.String shows error: 'String' is a type in 'System' and cannot be > used
> > in an expression. I have also tried using a GetType property on a
string,
> > but that has failed also. How can I pass and store the data type of the > > field? I want to do this so that I can later loop through the text
boxes
> > and do something like...
> >
> > MySQLCommand.Parameters.Add(dataTagCurrent.paramNa me,
> > dataTagCurrent.DataType).Value = txtLoop.Text
> >
> > Or something similar based on the control/data type, and also build the > SQL
> > Command string.
> >
> > Any help appreciated - thanks,
> > Mike
> >
> >
>
>


Nov 21 '05 #7

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

Similar topics

7
by: Matt | last post by:
In ASP, when we pass data between pages, we usually pass by query string. If we pass data by query string, that means we need to use submit button, not by regular button, and the form will pass to...
7
by: Jenny | last post by:
Hi, I have a class foo which will construct some objects in my code. some of the objects store int values into the data deque, while others store float values to the deque. template <class...
4
by: Dan | last post by:
Can anyone offer suggestions on how to do this or if it is possible? I have a form that uses a drop down box and 2 text fields. What I am trying to do is have the value of each text box set by...
5
by: Jason Huang | last post by:
Hi, In Global.cs, I have public string myString="". Another 2 forms are Form1.cs, Form2.cs. How do I use the Global.cs' myString to store a string in Form1 and then pass to Form2? Thanks for...
9
by: Alan Silver | last post by:
Hello, I'm a bit surprised at the amount of boilerplate code required to do standard data access in .NET and was looking for a way to improve matters. In Classic ASP, I used to have a common...
7
by: Andy | last post by:
Hi, I have a complicated question that I'm hoping someone can help me out with. I have a webpage that contains a plug-in. This plug-in can communicate/pass data with the webpage that contains it...
1
by: jadeivel756 | last post by:
I BADLY NEED YOUR HELP...... HELP... hOW TO Pass value to a struct type and permanently store the data after youve given the data.The programming language is C. My problem is that as I exit the...
4
by: jadeivel756 | last post by:
I BADLY NEED YOUR HELP...... HELP... hOW TO Pass value to a struct type and permanently store the data after youve given the data.The programming language is C. My problem is that as I exit the...
24
by: =?Utf-8?B?U3dhcHB5?= | last post by:
Can anyone suggest me to pass more parameters other than two parameter for events like the following? Event: Onbutton_click(object sender, EventArgs e)" Event handler: button.Click += new...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.