views:

387

answers:

2

In this case, the Visual Studio designer generates a method which takes the parameter as an int, even though the corresponding database column is specified as System.Int64.

This is the query specified in the "TableAdapter Query Configuration Wizard":

SELECT *
FROM my_table
WHERE "status_id" = ?

Again, status_id is of type System.Int64. This is what the designer generates:

public virtual DataSet1.MyDataTable GetDataByStatusId(int status_id) { ... }

Why isn't the parameter an Int64? Is this a bug in Visual Studio? (I'm using 2008 SP1.) I may end up just manually using the OdbcCommand class.

Edit: I'm using PostgreSQL, and the column is specified as type bigint.

A: 

Is the database type a long? The int64 will be created by the designer if you have an autonumber type in MS Access (which equates to a long (int64))... also, what database are you using?

Edit: With a bigint datatype, you should be able to use numbers up to 9223372036854775807... and with an int32, up to 2147483647. In other words, you are using the PostgreSQL equivalent of an int64, which can accept any int up to 9223372036854775807. An int32 works because the number will always be valid within that range. In .Net, you can implicitly convert between many of the number datatypes. For example, multiply an int by 1.0 and it will become a double. There is no need to explicitly cast or convert. You cannot, however, cast the other direction without dataloss.

jle
I'm using PostgreSQL, with datatype bigint.
Kyle Ryan
Well, I know an int32 works (because an int32 to int64 cast is always valid like you said), but I still need to use an int64 as a parameter. Visual Studio should have made it an int64. But I figured out how to change that.
Kyle Ryan
A: 

Okay, I figured it out. Visual Studio should have been smart enough to make the parameter a long (Int64), but here's how to set it manually:

In the Visual Studio Data Set Designer, select the method generated by the Add Query wizard--for instance, the item that says "FillByStatusId,GetDataByStatusId(status_id)". In the properties window, find the "Parameters" line and select the "..." This will allow you to set the "DbType" to Int64 (or whatever) manually, which fixed my problem.

Kyle Ryan