Click here to Skip to main content
15,887,386 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am doig Project In C# with database,,
Here is my Code...
C#
SqlDataAdapter da = new SqlDataAdapter("Select ID,DrugName,PurchasePrice,SellPrice,Stock from AddProduct where DrugName ='" + comboBox1.SelectedItems + "'", conn);
DataTable dt = new DataTable();
da.Fill(dt);
textBox1.Text = (dt.Rows[0]["ID"].ToString());
textBox2.Text = dt.Rows[1]["DrugName"].ToString();
textBox3.Text = (dt.Rows[2]["PurchasePrice"].ToString());
textBox4.Text = (dt.Rows[3]["SellPrice"].ToString());
textBox6.Text = (dt.Rows[4]["Stock"].ToString());

And these error occur:
The data types ntext and varchar are incompatible in the equal to operator.
Please help, what can i do?
Posted
Updated 10-Aug-12 15:52pm
v2
Comments
Kenneth Haugland 10-Aug-12 22:01pm    
comboBox1.SelectedItems ? How about SelectedItem.Name.ToString or somthing simular?
[no name] 11-Aug-12 1:16am    
And do not use string concatenation to construct SQL queries.

C#
SqlDataAdapter da = new SqlDataAdapter("Select ID,DrugName,PurchasePrice,SellPrice,Stock from AddProduct where DrugName ='" + comboBox1.SelectedText + "'", conn);

use selectedText and try again
 
Share this answer
 
v2
Comments
Volynsky Alex 11-Aug-12 3:43am    
Good answer
Hi,
This error comes when you use equal to"=" operator with text, ntext or image columns. If your column is of these datatype change it to nvarchar(max) or varchar(max)
 
Share this answer
 
SqlDataAdapter da = new SqlDataAdapter("Select ID,DrugName,PurchasePrice,SellPrice,Stock from AddProduct where DrugName ='" + comboBox1.SelectedText + "'", conn);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900