المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Error in retrieving data from SQL



C# Programming
05-22-2009, 05:54 AM
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