By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,693 Members | 1,230 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,693 IT Pros & Developers. It's quick & easy.

Pass / Store data type

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.