Home All Groups Group Topic Archive Search About

data type synchronization

Author
2 May 2007 5:30 PM
Alex
Hi,
I have three different data types coming out of my SQL tables that I
need to align with my VB code and the data set properties.  I'm
getting an error message that reads "SQL exception unhandled.  The
data types text and nvarchar are incompatible in the equal to
operator."  Here is the relevant code.

            Dim da As New SqlDataAdapter(strSQL, cn)
            da.SelectCommand.Parameters.AddWithValue("@OrderID",
tbOrderID.Text)


            Dim tbl As New DataTable("Orders")
            With tbl
                .Columns.Add("OrderID", GetType(String))
                .Columns.Add("Price", GetType(Decimal))
                .Columns.Add("Item", GetType(Integer))
            End With
            da.Fill(tbl)


Previously, I had all of the fields set to text in SQL, String in the
VB code and System.String in the data set properties.  Everything
executed fine.  However, when I tightened up my data types,
attempting
to change them to their correct types, the app crashed.  That was the
only thing that I changed between successful runs and the run-time
error.


So I suspect that I just have some sort of contradiction in how I
have
set the data types in the various settings (sql, vb code, data set).
I have attempted to synchronize these data types using:
      Text (sql), String (vb code), System.String (data set
properties);
      Money, Decimal, System.Decimal;
      Int, Integer, System.Int16.
No matter what I try, I get the exact same error.


Am I right or is the error message coming from somewhere else?  Also,
does anybody know of a reference that shows what data types are
"legal" matches between these different settings?


I appreciate any help.
Alex

Author
3 May 2007 7:04 AM
Miha Markic
Do you have any computed columns in DataTable?

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Show quote
"Alex" <fkm***@yahoo.com> wrote in message
news:1178127040.375310.306640@n59g2000hsh.googlegroups.com...
> Hi,
> I have three different data types coming out of my SQL tables that I
> need to align with my VB code and the data set properties.  I'm
> getting an error message that reads "SQL exception unhandled.  The
> data types text and nvarchar are incompatible in the equal to
> operator."  Here is the relevant code.
>
>            Dim da As New SqlDataAdapter(strSQL, cn)
>            da.SelectCommand.Parameters.AddWithValue("@OrderID",
> tbOrderID.Text)
>
>
>            Dim tbl As New DataTable("Orders")
>            With tbl
>                .Columns.Add("OrderID", GetType(String))
>                .Columns.Add("Price", GetType(Decimal))
>                .Columns.Add("Item", GetType(Integer))
>            End With
>            da.Fill(tbl)
>
>
> Previously, I had all of the fields set to text in SQL, String in the
> VB code and System.String in the data set properties.  Everything
> executed fine.  However, when I tightened up my data types,
> attempting
> to change them to their correct types, the app crashed.  That was the
> only thing that I changed between successful runs and the run-time
> error.
>
>
> So I suspect that I just have some sort of contradiction in how I
> have
> set the data types in the various settings (sql, vb code, data set).
> I have attempted to synchronize these data types using:
>      Text (sql), String (vb code), System.String (data set
> properties);
>      Money, Decimal, System.Decimal;
>      Int, Integer, System.Int16.
> No matter what I try, I get the exact same error.
>
>
> Am I right or is the error message coming from somewhere else?  Also,
> does anybody know of a reference that shows what data types are
> "legal" matches between these different settings?
>
>
> I appreciate any help.
> Alex
>
Author
3 May 2007 3:00 PM
Alex
No, it's very basic.  Three types of fields:  text, money, and integer.
Author
3 May 2007 3:19 PM
Miha Markic
What type is OrderID in the database?
How does your strSql look like?

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Show quote
"Alex" <fkm***@yahoo.com> wrote in message
news:1178204413.292937.86010@e65g2000hsc.googlegroups.com...
> No, it's very basic.  Three types of fields:  text, money, and integer.
>
Author
3 May 2007 4:21 PM
Alex
> What type is OrderID in the database?

text

> How does your strSql look like?

strSQL = "SELECT * FROM Orders WHERE OrderID = @OrderID"

Thanks Miha.  I appreciate you looking at this for me.
Author
3 May 2007 6:53 PM
Miha Markic
Hi Alex,

I see. Text is for storing large text fields and operators are not supported
on it.
You should change OrderID's text type to a varchar or nvarchar.
I think this should do.
--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Show quote
"Alex" <fkm***@yahoo.com> wrote in message
news:1178209304.814888.128450@c35g2000hsg.googlegroups.com...
>> What type is OrderID in the database?
>
> text
>
>> How does your strSql look like?
>
> strSQL = "SELECT * FROM Orders WHERE OrderID = @OrderID"
>
> Thanks Miha.  I appreciate you looking at this for me.
>
Author
4 May 2007 1:05 AM
Alex
Got it.  That solved the problem.  I'm pretty new to this, so I'm
working my way through these painful little roadblocks.  Do you know
of a web link that lists the various data types and what they can be
used for?

Thank you very much for your help!
Alex
Author
4 May 2007 9:23 AM
Miha Markic
SQL Server's books online is a good place to start
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
(same help file is included with SQL Server)
Other than that you should really pick a book on Sql Server...
--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Show quote
"Alex" <fkm***@yahoo.com> wrote in message
news:1178240704.875845.301240@q75g2000hsh.googlegroups.com...
> Got it.  That solved the problem.  I'm pretty new to this, so I'm
> working my way through these painful little roadblocks.  Do you know
> of a web link that lists the various data types and what they can be
> used for?
>
> Thank you very much for your help!
> Alex
>

AddThis Social Bookmark Button