Error in retrieving data from SQL
-
Dear brothers, I have read the book and searched from the internet. They told me the same way in retrieving data from SQL server. Unfortunately, it errors something when I do the same way. See my codes below : private void btn_login_Click(object sender, EventArgs e) { string sSQL = "SELECT USERNAME, USERPASSWORD FROM TBL_USER WHERE USERNAME = '" + this.txt_username.Text + "' AND USERPASSWORD = '" + this.txt_username.Text + "'"; SqlCommand sCommand = new SqlCommand(sSQL, dbConnection.sqlCnn); try { dbConnection.sqlCnn.Open(); SqlDataAdapter sReader = sCommand.ExecuteReader(); // It says : "Cannot implicitly convert type'System.Data.SqlClient.SqlDataReader' to 'System.Data.SqlClient.SqlDataAdapter'" while (sReader.Read() == true) { frm_main frmparents = new frm_main(); frmparents.ShowDialog(); } } catch (Exception Er) { MessageBox.Show(Er.Message, "Exception"); } Thanks for reading the entire article.
Chuon Visoth Angkor Wat - Cambodia asp.net - c sharp beginner
-
Dear brothers, I have read the book and searched from the internet. They told me the same way in retrieving data from SQL server. Unfortunately, it errors something when I do the same way. See my codes below : private void btn_login_Click(object sender, EventArgs e) { string sSQL = "SELECT USERNAME, USERPASSWORD FROM TBL_USER WHERE USERNAME = '" + this.txt_username.Text + "' AND USERPASSWORD = '" + this.txt_username.Text + "'"; SqlCommand sCommand = new SqlCommand(sSQL, dbConnection.sqlCnn); try { dbConnection.sqlCnn.Open(); SqlDataAdapter sReader = sCommand.ExecuteReader(); // It says : "Cannot implicitly convert type'System.Data.SqlClient.SqlDataReader' to 'System.Data.SqlClient.SqlDataAdapter'" while (sReader.Read() == true) { frm_main frmparents = new frm_main(); frmparents.ShowDialog(); } } catch (Exception Er) { MessageBox.Show(Er.Message, "Exception"); } Thanks for reading the entire article.
Chuon Visoth Angkor Wat - Cambodia asp.net - c sharp beginner
misCafe wrote:
AND USERPASSWORD = '" + this.txt_username.Text + "'";
:confused::confused::confused: BTW: normally one does not store the password, instead it gets hashed and it is the hash that gets stored and compared/searched.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
-
misCafe wrote:
AND USERPASSWORD = '" + this.txt_username.Text + "'";
:confused::confused::confused: BTW: normally one does not store the password, instead it gets hashed and it is the hash that gets stored and compared/searched.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
-
Oh yes, I have changed the text box. But it still errors when I press F5. Then how?
Chuon Visoth Angkor Wat - Cambodia asp.net - c sharp beginner
Hi, I have no experience with SqlDataAdapter, however the compiler is correct (obviously) when it says the result of ExecuteReader() is an SqlDataReader and not an SqlDataAdapter. I suggest you look at the relevant documentation and/or google for correct examples. :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
-
Dear brothers, I have read the book and searched from the internet. They told me the same way in retrieving data from SQL server. Unfortunately, it errors something when I do the same way. See my codes below : private void btn_login_Click(object sender, EventArgs e) { string sSQL = "SELECT USERNAME, USERPASSWORD FROM TBL_USER WHERE USERNAME = '" + this.txt_username.Text + "' AND USERPASSWORD = '" + this.txt_username.Text + "'"; SqlCommand sCommand = new SqlCommand(sSQL, dbConnection.sqlCnn); try { dbConnection.sqlCnn.Open(); SqlDataAdapter sReader = sCommand.ExecuteReader(); // It says : "Cannot implicitly convert type'System.Data.SqlClient.SqlDataReader' to 'System.Data.SqlClient.SqlDataAdapter'" while (sReader.Read() == true) { frm_main frmparents = new frm_main(); frmparents.ShowDialog(); } } catch (Exception Er) { MessageBox.Show(Er.Message, "Exception"); } Thanks for reading the entire article.
Chuon Visoth Angkor Wat - Cambodia asp.net - c sharp beginner
misCafe wrote:
SqlDataAdapter sReader = sCommand.ExecuteReader();
This is where the problem is.
ExecuteReader
method returns aDataReader
object and NOT theDataAdapter
object. In case you need to use theDataAdapter
, initialize it using the parameterized constructor and then use itsFill
method. ObjectBrowser will help you finding about these.जय हिंद
-
misCafe wrote:
SqlDataAdapter sReader = sCommand.ExecuteReader();
This is where the problem is.
ExecuteReader
method returns aDataReader
object and NOT theDataAdapter
object. In case you need to use theDataAdapter
, initialize it using the parameterized constructor and then use itsFill
method. ObjectBrowser will help you finding about these.जय हिंद
-
Many thanks for taking a part on this article ;)
Chuon Visoth Angkor Wat - Cambodia asp.net - c sharp beginner
-
misCafe wrote:
SqlDataAdapter sReader = sCommand.ExecuteReader();
This is where the problem is.
ExecuteReader
method returns aDataReader
object and NOT theDataAdapter
object. In case you need to use theDataAdapter
, initialize it using the parameterized constructor and then use itsFill
method. ObjectBrowser will help you finding about these.जय हिंद