harvard_isaac

hello all;

i am tryign to update my database using a dataadapter but i think i have a problem using parametres..

can anyone help me with the code below :

using (OleDbConnection conn= new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\\Visual Studio 2005\\WebSites\\AFET\\App_Data\\afetler.mdb"))

{

da.UpdateCommand= new OleDbCommand("UPDATE sehir SET SEHIR = " +

"WHERE SEHIR = ", conn);

da.UpdateCommand.Parameters.Add("@SEHIR", OleDbType.VarChar, 12, "SEHIR"); /// since both of the paranmeters requeire SEHIR= how will i overcome it

da.UpdateCommand.Parameters.Add("@SEHIR", OleDbType.VarChar, 12, "SEHIR");

da.UpdateCommand.Parameters[0].Value = "Ankara";da.UpdateCommand.Parameters[1].Value = " zmir";

dr = dt.NewRow();

dr["SEHIR"] = "Anka";

dt.Rows.Add(dr);

dr = dt.Rows[0];

dr["SEHIR"] = "Ada";

da.Update(dt);

}

i just wanted to change the city names ; but i do not know how to add teh values in the correct order.. if i wanted to edit some more columns other than SEHIR than how would i use my code to overcome this problem



Re: .NET Framework Data Access and Storage oledbdataadapter parameter problem

Paul P Clement IV

The OLEDB provider under ADO.NET does not support named parameters. You simply add them in the order that they appear in the SQL statement. In addition, it looks like you're missing a space after the first parameter.






Re: .NET Framework Data Access and Storage oledbdataadapter parameter problem

harvard_isaac

so if i delete that space character before ' ' then how should i add the parameters without naming,

can this be a solution

updatecomand.parameters[0] = updatecommand.parameters.add().value="SOMEVALUE" ;

updatecomand.parameters[1] = updatecommand.parameters.add().value="SOMEVALUE" ;

and so on....

or what is your suggesiton to add the parameters..





Re: .NET Framework Data Access and Storage oledbdataadapter parameter problem

Paul P Clement IV

There is no space character in between your first parameter and the WHERE keyword. You need to add a space there.


You can use parameter names in the Parameters.Add statement but they are ignored. I would just use a different name for each parameter so as not to cause confusion in your code. Also, I would remove the fourth argument "SEHIR" from the Parameters.Add statement.