I am working with .sdf database when i execute the select query i get the following error: Data conv

Posted by Sp under ASP.NET on 11/1/2010 | Points: 10 | Views : 11876 | Status : [Member] | Replies : 1
I am working with .sdf database when i execute the select query i get the following error:
Data conversion failed. [ OLE DB status value (if known) = 2 ]
P.PatientID AS [Patient Id],
P.PathentName AS [Patient name],
P.BirthDate AS [Birth Date],
P.Patientsex AS [Patient Sex],
ST.Study Date,
ST.Accessionnumber AS [Acession Number],
ST.ReferDrName AS [Refer Dr.]
Patients P INNER JOIN Studies ST
ON P.PatientID = ST.PatientID
This is my code:

private void pictureBox1_Click(object sender, EventArgs e)
SqlCeConnection con = new SqlCeConnection();
con.ConnectionString = "Data Source=Dicom.sdf;Persist Security Info=False;";

string query=null;
query = "SELECT P.PatientId AS [Patient Id], P.Name AS [Patient name], P.BirthDate AS [Birth Date], P.Sex AS [Patient Sex], ST.StudyDescription, ST.StudyDate AS Date, ST.AccessionNumber AS [Acession Number], ST.ReferDrName AS [Refer Dr.] FROM Patients AS P INNER JOIN Studies AS ST ON P.PatientId = ST.PatientId WHERE (P.PatientId = 1234567890)";
SqlCeDataAdapter adp = new SqlCeDataAdapter(query, "Data Source=Dicom.sdf;Persist Security Info=False;");
SqlCeCommandBuilder commandBuilder = new SqlCeCommandBuilder(adp);
DataTable dt = new DataTable();
dt.Locale = System.Globalization.CultureInfo.InvariantCulture;
// StudiesbindingSource.DataSource = dt;

dataGridViewStudies.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);// Resize the DataGridView columns to fit the newly loaded content.
// finally bind the data to the grid

dataGridViewStudies.DataSource = dt;

dataGridViewStudies.ReadOnly = true;
dataGridViewStudies.Visible = true;


Posted by: SheoNarayan on: 11/1/2010 [Administrator] HonoraryPlatinum | Points: 25

This looks like a simple data conversion error where you might be converting integer from string that can't be. For example you can't convert "s" to an integer value. Or you may not insert 2 into a bit data type of field in the Sql, it accepts either 0 or 1.

Does this provide any line number, can you copy-paste the exact error?

Sheo Narayan

Sp, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response