Developer forum

Forum » CMS - Standard features » RE: Inserting data with parameter in razor

RE: Inserting data with parameter in razor

Jan Sangill
Reply

Hej,

 

I dette eksempel i razor template:

 

var inserted_to_db = Dynamicweb.Database.ExecuteNonQuery("INSERT INTO DB_bedommelse_rating(DB_bedommelse_rating_rating,DB_bedommelse_rating_url) VALUES(@review_val,'fsfsd')");

Får jeg en fejl, fordi at @review_val ikke er defineret via en command går jeg udfra. (command.Parameters.Add)

Hvordan ville man gøre dette via Dynamicweb.Database.ExecuteNonQuery.

Nogle der kan give et eksempel?


Replies

 
Nicolai Høeg Pedersen
Reply

You need to do something like this using the Dynamicweb API:

Dim connection As IDbConnection = Database.CreateConnection()

Dim command As IDbCommand = connection.CreateCommand()

command.CommandText = "INSERT INTO DB_bedommelse_rating(DB_bedommelse_rating_rating,DB_bedommelse_rating_url) VALUES(@review_val,'fsfsd')"

Database.AddStringParam(command, "@review_val", "5")

command.ExecuteNonQuery()

 

See docs for other Add*Param methods:

http://developer.dynamicweb-cms.com/api8/#Dynamicweb~Dynamicweb.Database_members.html

 
Nicolai Høeg Pedersen
Reply

By the way - we do not understand Danish in the forums :-).

 
Jan Sangill
Reply

Hi Nicolai,

Yes, I forgot english for just a second there:)

The reply got me on the correct path. Perfect. Thank you for the assistance!

/jan

 

You must be logged in to post in the forum