views:

33

answers:

2

I would like to select a record from my table based on a GUID using the following approach:

dim rows() as MyDataSet.MyTableRow = dataset.MyTable.Select("id = " & Guid.NewGuid.ToString)

but I get the following exception:

System.Data.EvaluateException was unhandled
Message="Cannot perform '=' operation on System.Guid and System.Int32.

What is the best way to select a record based on a GUID using vbasic.net from MS Sql Server?

A: 

You need to use GUID's in single quotes - sample in C#:

string filter = string.Format("id = '{0}'", Guid.NewGuid.ToString());
DataRow[] rows = dataset.MyTable.Select(filter);
marc_s
A: 

You also need to add parens around the single quotes like so...

"id = ('" & Guid.NewGuid.ToString & "')"
Carter