- Home /
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.
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?
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.
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)*
Your answer
Follow this Question
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