Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by tonywcosta · Apr 11, 2014 at 11:10 PM · c#databasesql

MYSQL How do get all of my SELECT information?

I have a very simple select command as noted below.

 dbCommand.CommandText = "SELECT * FROM ticket WHERE Product = '" + searchModel +"'";

This constantly errors out with

 InvalidCastException: Cannot cast from source type to destination type.

However, when I change the select to this

 dbCommand.CommandText = "SELECT * FROM ticket WHERE ID = '166777'";

The command is able to find all of my values from that column without a problem.

I have been stuck on this for a couple of days with no end in sight. This is a project for my work, and I need to understand what I am doing wrong.

Any help is GREATLY appreciated.

Thank you.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image getyour411 · Apr 11, 2014 at 11:39 PM 0
Share

What type is search$$anonymous$$odel? Does your db parser need an escape sequence before the single ticks? Your example changed WHERE Product and WHERE ID, are they different types?

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by tonywcosta · Apr 11, 2014 at 11:50 PM

This was answered by me. It appears that all I need to do is ask the question and the answer will come to me :)

However, any insight is always appreciated.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by Kamuiyshirou · Apr 30, 2014 at 10:17 PM

1 - I downloaded the Connector / Net (Net & Mono version 2.0.).

2 - Insert the mysql.data.dll the project.

3 - I configured. NET in my project = Edit / Project Settings / Player / Optimization / Api Compatibility Level>. NET 2.0.

4 - I created this script below:

 using UnityEngine;
 using System.Collections;
 using MySql.Data.MySqlClient;
 
 public class ConexaoBanco : MonoBehaviour {
 private string source;
 private MySqlConnection conexao;
 
 void Start () {
 
 source =     "Server=localhost;" +
              "Database = yourDataBaseSQL;" +  
              "User ID = root;" +
              "Pooling = false;" +
              "Password= yourpassword";
 
 
        ConexaoBanco(source);
        Listar (conexao);
 
    }
 
    // Update is called once per frame
    void Update () {
 
    }
 
    void ConectarBanco (string _source){
    conexao = new MySqlConnection (_source);
    conexao.Open ();
    }
 
 void Listar (MySqlConnection _conexao){
 MySqlCommand comando = _conexao.CreateCommand();
 comando.CommandText = "Select * from voz_principal";
 MySqlDataReader dados = comando.ExecuteReader();
 
 while (dados.Read()){
    string nome = (string)dados["nome"];
 
 
           Debug.Log("Usuario " + nome);
 
         }
 
      }
 
    }

///////////////////////////////////

*(Reference: https://www.youtube.com/watch?v=hpwe_BIhCHg&list=UUC2k-SBDIRK1Jg1vJSYOBYg)*

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Microsoft SQL Server error. 0 Answers

SQLite3 AttachDatabase command won't work 0 Answers

Multiple Cars not working 1 Answer

Access a MySQL database via C# ? 2 Answers

TypeLoadException with libraries in C# 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges