C# [SQL Data Read]

09/03/2014 01:28 ​Exo#1
/solved
09/03/2014 07:41 Mostey#2
The sql reader does not contain the result, it reads from the stream that contains the result. Therefore, converting the reader to a string will probably result in the class name.
09/03/2014 11:31 ​Exo#3
Quote:
Originally Posted by Mostey View Post
The sql reader does not contain the result, it reads from the stream that contains the result. Therefore, converting the reader to a string will probably result in the class name.
So any idea how to get the result to a string?
09/03/2014 15:22 Assault IX#4
Code:
<command>.CommandText = "SELECT Row FROM Table";
string txtNews = Convert.ToString(command.ExecuteScalar());
<richTextBox1>.Text = txtNews;
09/03/2014 15:28 Black Tiger ツ#5
Quote:
Originally Posted by xExorcist View Post
So any idea how to get the result to a string?
Don't forget to select a table from your DB.

Code:
            private string _readStringDB1;
            private string _readStringDB2;
            private string _readStringDB3;
            
            SqlDataReader reader = Command.ExecuteReader();
            while (reader.Read())
            {
                _readStringDB1 = reader.GetString(0); //First column
                _readStringDB2 = reader.GetString(1); //Second column
                _readStringDB3 = reader.GetString(2); //Third column
            }
09/03/2014 16:05 Black Tiger ツ#6
Quote:
Originally Posted by xExorcist View Post
I am gett ofng "0" as a string
cmd.CommandText = ("Select * FROM _Char");
cmd.Connection = sqlconn.cnn;

string txtNews = Convert.ToString(cmd.ExecuteScalar());
richTextBox1.Text = txtNews;
The result should be like this


There's only 1 row in the table [Only registered and activated users can see links. Click Here To Register...]
ExecuteScalar can only handle one column / cell. If there is multiple value it will take the first column of the first row.
Use ExecuteReader instead.

Best approach would be LinQ to SQL: [Only registered and activated users can see links. Click Here To Register...]
09/03/2014 16:32 ​Exo#7
Quote:
Originally Posted by Black Tiger ツ View Post
ExecuteScalar can only handle one column / cell. If there is multiple value it will take the first column of the first row.
Use ExecuteReader instead.

Best approach would be LinQ to SQL: [Only registered and activated users can see links. Click Here To Register...]
Reader just returns the "System.Data.SqlClient.SqlDataReader" as text...
09/09/2014 08:04 Mostey#8
Why'd you need that? Just model your data properly and store the inserted objects.

If you want to get the last inserted ID (due to the AI modifier), you may query this as follows:

Code:
SELECT LAST_INSERT_ID()
But I'm sure that your library can even handle that, might be stored as property in the result class?