Greetings..
Yesterday I posted a code for loading method where I was looking for help and thanks for everyone who contributed...
Let me take you back from the code that i posted while looking for help...
1. Below it is my code for loading method to the form
-this is the code I posted when I was stuck...
private void formloaddata()
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings ["ConnectionString01"].ConnectionString);
string strquery = "Select UserID,Username,Password,Fullname,Surname,Email Address,Country,Province";
SqlDataReader read = new SqlDataReader(conn, strquery); GridView1.DataBind();
}
2. This is the solution I got yesterday from one of the site members.
-solution I got was having some erros but I managed to correct them and modify the code
private void formloaddata()
{
SqlDataReader read SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString01"].ConnectionString);
conn.open
string strquery = "Select UserID,Username,Password,Fullname,Surname,Email Address,Country,Province from "Write your TableName"";
SqlCommand cmd=new SqlCommand(strquery,conn);
read = cmd.ExecutenonQuery();
if read.hasrows
{
read.Read(); textbox1.text=read("UserID");
textbox3.text=read("Password");
textbox4.text=read("Fullname");
textbox5.text=read("Surname");
textbox6.text=read("Email ");
textbox7.text=read("Address");
textbox8.text=read("Country");
textbox9.text=read("Province");
}
}
3.After the above code, I managed to rectify the mistakes and modify the code
-I have modified the code and it gives me errors
-I have commented on the errors so that you can see the errors on the codes
Erros that it gives,
*//Error :Cannot implicitly convert type 'int' to 'System.Data.SqlClient.SqlDataReader'
*//Errors :for code below 'read' is a 'variable' but is used like a 'method'
Find my code below;
private void formloaddata()
{
SqlDataReader read;
SqlCommand comm = new SqlCommand(ConfigurationManager.ConnectionStrings["ConnectionString01"].ConnectionString);
conn.Open();
string strquery = "select UserID,Username,Password,Fullname,Surname,Email Address,Country,Province from tblreg";
SqlCommand comd = new SqlCommand(strquery, conn);
*//Error: Cannot implicitly convert type 'int' to 'System.Data.SqlClient.SqlDataReader'
read = comd.ExecuteNonQuery();
if(read.HasRows)
{
while (read.Read())
{
*//Error: For code below 'read' is a 'variable' but is used like a 'method'
txtuser.Text = read("Username");
txtPass.Text = read("Password");
txtFulln.Text = read("Fullname");
txtSurname.Text = read("Surname");
txtemail.Text = read("Email Address");
dropCountry.Text = read("Country");
dropProvince.Text = read("province");
}
}
try
{
conn.Close();
}
catch (Exception ex)
{
Response.Write("Error");
}
finally
{
Response.Write("Executed");
}
1. Can you please correct me on those erros so that next time I will now the reason.
2. Can you please check my try catch method if it is fine..
Thanks for your help..