0

I'm trying to cast value from database to local variable. The value and the local variable are with the same type (both string), but it seems i can't work it through. If i add .toString() it looks fine (didn't test but no errors). I checked Faqs and some youtube videos and there was no problem and they use same method of casting. The code below gives me this error:

Error CS0266 Cannot implicitly convert type 'object' to 'string'. An explicit conversion exists (are you missing a cast?)

Additional informations: using Adodb v7.0.3300.0, Visualstudio 2017 C#.

var db = Globals.mysql.DB_RS;
db.Open("SELECT * FROM accounts WHERE username='"+user+"'", Globals.mysql.DB_CONN, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic);
Globals.player[index].username = db.Fields["username"].Value;
Ňɏssa Pøngjǣrdenlarp
  • 38,411
  • 12
  • 59
  • 178
Z odiaq
  • 1
  • 1
  • 2
    You have a SQL injection vulnerability. – SLaks Mar 08 '18 at 21:10
  • I suggest have a squiz at https://github.com/StackExchange/Dapper . It will solve both of your problems at the same time. – mjwills Mar 08 '18 at 21:10
  • 2
    Dont+concat+strings+and+values+like+that. use Parameters. Any reason you are not using the ADO.NET provider lovingly crafted to work with MySql? please read [ask] and take the [tour] – Ňɏssa Pøngjǣrdenlarp Mar 08 '18 at 21:11
  • Okey thank you, now i see. But why does it work in the tutorials i watched? what could be the difference?. @Plutonix It was an open source project and i decided to modify it. I'll definitely check ADO.NET. And i'm sorry if i've done a mistake asking the question, i'm trying my best to keep it clear and doesn't break any rules. – Z odiaq Mar 08 '18 at 21:36
  • If you are *really* concerned about breaking the rules, the first thing would be to *read* some of the site guidelines. You checked a box saying you'd do this when you signed up, but you havent. Read [ask] and take the [tour] – Ňɏssa Pøngjǣrdenlarp Mar 08 '18 at 22:47

0 Answers0