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

nycdude

Пользователь
Joined
May 6, 2018
Messages
57
Reaction score
1
Points
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.

Code:
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.
 

Attachments

lokiys

Moderator
Joined
Feb 1, 2012
Messages
4,920
Reaction score
1,203
Points
113

nycdude

Пользователь
Joined
May 6, 2018
Messages
57
Reaction score
1
Points
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
Joined
Feb 1, 2012
Messages
4,920
Reaction score
1,203
Points
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
 
  • Thank you
Reactions: nycdude

nycdude

Пользователь
Joined
May 6, 2018
Messages
57
Reaction score
1
Points
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).

Code:
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.
 
Last edited:

lokiys

Moderator
Joined
Feb 1, 2012
Messages
4,920
Reaction score
1,203
Points
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).

Code:
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

Пользователь
Joined
May 6, 2018
Messages
57
Reaction score
1
Points
8
If Connection is successful and your SQL request is correct. Then all should be fine.
I'm using PHPMyAdmin Mysql, is there anything special I need to access it? Because this is just weird if you say it should be good but it's not.
 

nycdude

Пользователь
Joined
May 6, 2018
Messages
57
Reaction score
1
Points
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
Joined
Jan 2, 2017
Messages
527
Reaction score
113
Points
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.
 

Attachments

  • Thank you
Reactions: nycdude

Users Who Are Viewing This Thread (Total: 1, Members: 0, Guests: 1)