error:datatype mismatch
-
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string str = "Select * From Vendor Where(VendorID= '"+ DropDownList1.SelectedValue +"')";
OleDbCommand cmd = new OleDbCommand(str, conn);
OleDbDataReader dr=null;
conn.Open();
dr = cmd.ExecuteReader();
while (dr.Read())
{
txtvendorname.Text = dr["VendorName"].ToString();
}
conn.Close();
}hi i am getting data type mismatch error on executin this code.plz guide...
-
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string str = "Select * From Vendor Where(VendorID= '"+ DropDownList1.SelectedValue +"')";
OleDbCommand cmd = new OleDbCommand(str, conn);
OleDbDataReader dr=null;
conn.Open();
dr = cmd.ExecuteReader();
while (dr.Read())
{
txtvendorname.Text = dr["VendorName"].ToString();
}
conn.Close();
}hi i am getting data type mismatch error on executin this code.plz guide...
mylogics wrote:
data type mismatch error
I have couple of suggestions - 1. Instead of the SELECT * FROM Vendor, use the columnames you need e.g. SELECT VENDOR_NAME,VENDOR_ID FROM Vendor. 2. Instead of dr[columnname] use dr.GetInt32(index) or dr.GetString(index). See the example here[^].
Regards, Arindam Sinha MyBlog - http://arindamsinha.wordpress.com/ Please give your feedback on this answer.
-
mylogics wrote:
data type mismatch error
I have couple of suggestions - 1. Instead of the SELECT * FROM Vendor, use the columnames you need e.g. SELECT VENDOR_NAME,VENDOR_ID FROM Vendor. 2. Instead of dr[columnname] use dr.GetInt32(index) or dr.GetString(index). See the example here[^].
Regards, Arindam Sinha MyBlog - http://arindamsinha.wordpress.com/ Please give your feedback on this answer.
-
Can you put a try catch and find out the trace? Also in which line you are getting that? It would be good if you can provide the data types of your table columns as well.
Regards, Arindam Sinha MyBlog - http://arindamsinha.wordpress.com/ Please give your feedback on this answer.
modified on Saturday, August 29, 2009 7:46 AM
-
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string str = "Select * From Vendor Where(VendorID= '"+ DropDownList1.SelectedValue +"')";
OleDbCommand cmd = new OleDbCommand(str, conn);
OleDbDataReader dr=null;
conn.Open();
dr = cmd.ExecuteReader();
while (dr.Read())
{
txtvendorname.Text = dr["VendorName"].ToString();
}
conn.Close();
}hi i am getting data type mismatch error on executin this code.plz guide...
mylogics wrote:
string str = "Select * From Vendor Where(VendorID= '"+ DropDownList1.SelectedValue +"')";
check whether VendorID is int or string, if VendorID is int then use "DropDownList1.SelectedValue" if VendorID is string then use '"DropDownList1.SelectedValue"'
Padmanabhan My Articles: Articles[^] My latest Article: Word Automation[^]
-
mylogics wrote:
string str = "Select * From Vendor Where(VendorID= '"+ DropDownList1.SelectedValue +"')";
check whether VendorID is int or string, if VendorID is int then use "DropDownList1.SelectedValue" if VendorID is string then use '"DropDownList1.SelectedValue"'
Padmanabhan My Articles: Articles[^] My latest Article: Word Automation[^]
-
actually m using access database n the vendorID datatype is autonumber previously when the vendorID was text it was workin f9.... wat shud i do... ERROR:DATATYPE MISMATCH IN CRITERIA EXPRESSION
then remove single quotes and try
Padmanabhan My Articles: Articles[^] My latest Article: Word Automation[^]
-
actually m using access database n the vendorID datatype is autonumber previously when the vendorID was text it was workin f9.... wat shud i do... ERROR:DATATYPE MISMATCH IN CRITERIA EXPRESSION
You can try this -
string str = "Select * From Vendor Where(VendorID= "+ DropDownList1.SelectedValue +")";
Regards, Arindam Sinha MyBlog - http://arindamsinha.wordpress.com/ Please give your feedback on this answer.
-
then remove single quotes and try
Padmanabhan My Articles: Articles[^] My latest Article: Word Automation[^]
-
it gives error while compiling.i think the problem is with dtatype of vendorID.previously when datatype was text it worked f9.
what is the error... what is the value you got in the dropdown selected value....
Padmanabhan My Articles: Articles[^] My latest Article: Word Automation[^]
-
what is the error... what is the value you got in the dropdown selected value....
Padmanabhan My Articles: Articles[^] My latest Article: Word Automation[^]
-
it will render in back end as, select * from table where id is '2'-- this is wrong because ''is for string...... so we have to mention as, select * from table where id is 2 and for name field, select name from table where name = 'xyz'-- this is correct
Padmanabhan My Articles: Articles[^] My latest Article: Word Automation[^]
-
it will render in back end as, select * from table where id is '2'-- this is wrong because ''is for string...... so we have to mention as, select * from table where id is 2 and for name field, select name from table where name = 'xyz'-- this is correct
Padmanabhan My Articles: Articles[^] My latest Article: Word Automation[^]
-
One small suggestion..The when you build a query string try to execute that in the DB first. With quotes query would have given you the error in DB itself.
Regards, Arindam Sinha MyBlog - http://arindamsinha.wordpress.com/ Please give your feedback on this answer.
-
One small suggestion..The when you build a query string try to execute that in the DB first. With quotes query would have given you the error in DB itself.
Regards, Arindam Sinha MyBlog - http://arindamsinha.wordpress.com/ Please give your feedback on this answer.