help with SQL queries

  • Thread starter Thread starter agassi
  • Start date Start date
A

agassi

hi guys,
i want to select from the database using a query with a variable name.
but it's not working. can you tell me what is wrong with my code(i'm
using C++.NET):

int index = textBox1->Text->ToInt32(0);

myadapter1 = new Data::OleDb::OleDbDataAdapter("SELECT AssetID, Make,
Model, YearAcquired, Price, Description FROM CompanyAssets WHERE
CompanyAssets.AssetCategoryID = & index &",conn1);
myadapter1->Fill(mydataset);

i think the problem comes from : & index & but i dont know to solve
it. please help!!
 
hey there,

index = somevalue from somewhere

WHERE CompanyAssets.AssetCategoryID =" & index, conn1)


HTH - Sean
 
Hi,
1) index is a reserved word, you shouldn't use it in an sql statement as a variable name
2) replace & index & with @id (i. e. CompanyAssets.AssetCategoryID = @id), this is the syntax to use parameters in sql. Then just do myadapter1.SelectCommand.Parameters["@id"].Value = 'whatever'
 
thank you for replying
i' ve tried ur code but it didnt work. do u have any other idea?



*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
hi there,
thanks for replying. i've tried ur code but it didnt work. i want to
remind u that i'm working with vc++.net. do u have any other idea?



*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Back
Top