Trying to do Rostonix video to connect to DB with c#

nycdude

Пользователь
Регистрация
06.05.2018
Сообщения
57
Благодарностей
1
Баллы
8
Hello all,

I'm trying to do this video here:

I've followed it to a T I believe, even added the external assemblies and all.

Код:
var result = String.Empty;
var command = new MySql.Data.MySqlClient.MySqlCommand();
command.CommandText = "SELECT * FROM wpdatatable_17_2 ORDER BY RAND() LIMIT 1;";
var connectionSTring = "server=999.999.99.9;user=xxxxxx;database=xxxxxx;port=3306;password=xxxxxx;";
try
{
    command.Connection = new MySql.Data.MySqlClient.MySqlConnection(connectionSTring);
}
catch (Exception e)
{
    result = "Mysql error";
}
if (result!=String.Empty)
{
    return result;
}
try
{
    command.Connection.Open();
    var read = command.ExecuteReader();
    while (read.Read())
    {
        project.Variables["dmn"].Value = read["dmn"].ToString();
}
catch (MySql.Data.MySqlClient.MySqlException e)
{
    result =  "Mysql error "+e.Message;
}
finally
{
    command.Connection.Close();
}
return result;
I have the C# code going to a variable.

Thanks for any help, I've been looking through the forum and have seen many different examples on how to use Mysql database, but they don't help me because my knowledge is rather limited for now, and the examples here never really explain fully on how to do it.
 

Вложения

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 771
Благодарностей
1 184
Баллы
113

nycdude

Пользователь
Регистрация
06.05.2018
Сообщения
57
Благодарностей
1
Баллы
8
Hi. and what is the problem?
If You are not sure how to develop in C# then You can use zenno actions for databases https://zennolab.com/wiki/en:working-with-databases
The problem is I can't call data from the DB using the code above. Halfway through the video I coded the same as rostonix and did the connection test, and it worked. Towards the end of the video, I have copied the code the same (except my table stuff and just want one col) and it just won't get anything, it fails.

The link you provided working with databases, I have looked over pretty good and made a connection and everything ... but I don't understand what or how to use the request forms. How to write and take data I get stuck there. Is there a reference to the commands I can use in that? I don't understand how to use the parameters and stuff, the link doesn't show much for noobs like me.
 

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 771
Благодарностей
1 184
Баллы
113
The problem is I can't call data from the DB using the code above. Halfway through the video I coded the same as rostonix and did the connection test, and it worked. Towards the end of the video, I have copied the code the same (except my table stuff and just want one col) and it just won't get anything, it fails.

The link you provided working with databases, I have looked over pretty good and made a connection and everything ... but I don't understand what or how to use the request forms. How to write and take data I get stuck there. Is there a reference to the commands I can use in that? I don't understand how to use the parameters and stuff, the link doesn't show much for noobs like me.
The link shows what You have to know from zenno side...
To get or post data from DB You have to use SQL requests
Example: https://www.w3schools.com/sql/sql_select.asp
 
  • Спасибо
Реакции: nycdude

nycdude

Пользователь
Регистрация
06.05.2018
Сообщения
57
Благодарностей
1
Баллы
8
Hello,
So I'm still unable to work with a mysql database (super-noob here). Per this link here: https://www.w3schools.com/sql/sql_select.asp I'm just trying to get started to get all of one column into a list.

I can connect just fine, there are three tables and I can't get at it. Remote and everything is checked out (connection OK).

Код:
SELECT col FROM Mytable;
I've tried several column seperators: , ; "," (also: {-String.Space-}, {-String.Tab-}, {-String.Enter-})

Still can't get it to get data, the connection is fine etc.

Thanks for reading.
 
Последнее редактирование:

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 771
Благодарностей
1 184
Баллы
113
Hello,
So I'm still unable to work with a mysql database (super-noob here). Per this link here: https://www.w3schools.com/sql/sql_select.asp I'm just trying to get started to get all of one column into a list.

I can connect just fine, there are three tables and I can't get at it. Remote and everything is checked out (connection OK).

Код:
SELECT col FROM Mytable;
I've tried several column seperators: , ; "," (also: {-String.Space-}, {-String.Tab-}, {-String.Enter-})

Still can't get it to get data, the connection is fine etc.

Thanks for reading.

If Connection is successful and your SQL request is correct. Then all should be fine.
 

nycdude

Пользователь
Регистрация
06.05.2018
Сообщения
57
Благодарностей
1
Баллы
8

nycdude

Пользователь
Регистрация
06.05.2018
Сообщения
57
Благодарностей
1
Баллы
8
OK, I made a new project to test and it works, column separator is space ... but it still doesn't work with exact settings in the project I need it. Why does it work in a fresh new project but not in my old project where I need it?

Column separator is {-String.Space-} btw.

Thanks
 

EtaLasquera

Client
Регистрация
02.01.2017
Сообщения
524
Благодарностей
112
Баллы
43
I don't know why you need C# to use database select, here is a sample about how to use database search sample.
We use SQL server, just change your database to mySQL as well change database con string as you need.
 

Вложения

  • Спасибо
Реакции: nycdude

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)