Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > .NET Languages
You last visited: Today at 12:49

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



C# [SQL Data Read]

Discussion on C# [SQL Data Read] within the .NET Languages forum part of the Coders Den category.

Reply
 
Old   #1


 
​Exo's Avatar
 
elite*gold: 28
Join Date: Aug 2014
Posts: 4,096
Received Thanks: 2,653
Arrow C# [SQL Data Read]

/solved
​Exo is offline  
Old 09/03/2014, 07:41   #2


 
elite*gold: 1091
Join Date: Jun 2007
Posts: 19,836
Received Thanks: 7,180
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.
Mostey is offline  
Old 09/03/2014, 11:31   #3


 
​Exo's Avatar
 
elite*gold: 28
Join Date: Aug 2014
Posts: 4,096
Received Thanks: 2,653
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?
​Exo is offline  
Old 09/03/2014, 15:22   #4
 
Assault IX's Avatar
 
elite*gold: 12
Join Date: Jun 2012
Posts: 782
Received Thanks: 215
Code:
<command>.CommandText = "SELECT Row FROM Table";
string txtNews = Convert.ToString(command.ExecuteScalar());
<richTextBox1>.Text = txtNews;
Assault IX is offline  
Thanks
1 User
Old 09/03/2014, 15:28   #5
 
elite*gold: 1
Join Date: Aug 2013
Posts: 1,898
Received Thanks: 1,346
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
            }
Black Tiger ツ is offline  
Thanks
1 User
Old 09/03/2014, 16:05   #6
 
elite*gold: 1
Join Date: Aug 2013
Posts: 1,898
Received Thanks: 1,346
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
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:
Black Tiger ツ is offline  
Old 09/03/2014, 16:32   #7


 
​Exo's Avatar
 
elite*gold: 28
Join Date: Aug 2014
Posts: 4,096
Received Thanks: 2,653
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:
Reader just returns the "System.Data.SqlClient.SqlDataReader" as text...
​Exo is offline  
Old 09/09/2014, 08:04   #8


 
elite*gold: 1091
Join Date: Jun 2007
Posts: 19,836
Received Thanks: 7,180
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?
Mostey is offline  
Reply

Tags
c#, read, sql


Similar Threads Similar Threads
Failed to read data from PFO no fix!!!!!!
07/02/2017 - SRO Private Server - 13 Replies
hi all , i use cracked version of mbot and i get this error Failed to read data from PFO when i try to choose the sro folder i searched many times on many forums and no even one come close for fix it any idea how to fix the problem Thanks.
Help with read data
11/08/2013 - AutoIt - 5 Replies
i need help with reading data from ini when i open file it returns me 1 and not content of file here is script #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <WindowsConstants.au3>
[mBot] Failed To Read Data From Pfo
03/18/2013 - SRO Private Server - 5 Replies
Its giving this error when i click bot :S If i remove and setup the game again it have fixed. But i want a easy fix :)) Thanks
cant read data.pak w/winhex
07/10/2011 - Dekaron - 11 Replies
ok i forgot what i did to read the data pk. but now i cant read it, it either opens like "1F 0E 3F.." or "#$#%#$@...." can someone tell me what option to make it in text and numeric that is readable. I chose text only under "view" but it shoews all %^&&*#^$&#..plz help



All times are GMT +1. The time now is 12:57.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.