N
nasirmajor
Dear All,
im fetching record from database using datareader, and is displaying
them in the textboxes.
when user change the text fields and then presses the update button the
record should be updated but what happen is: form is postedback but no
change happen to database and also textboxes return to there original
state i.e previous record(enableviewstate is false/same result with
true).
small code is here:
----------------------------------------------------------
<script runat="server">
SqlConnection c = new SqlConnection("user id=sa;password=;Initial
Catalog=jobsdbbackup;Data Source=localhost;Integrated Security=SSPI;");
protected void Page_Load(object sender, EventArgs e)
{
string email = "";
string firstname = "";
string lastname = "";
string strOleDb = "SELECT email,firstname,lastname FROM
tbl_jobreg where email='(e-mail address removed)'";
SqlCommand command = new SqlCommand(strOleDb, c);
c.Open();
SqlDataReader Reader;
Reader = command.ExecuteReader();
while (Reader.Read())
{
email = Reader.GetString(0);
firstname = Reader.GetString(1);
lastname = Reader.GetString(2);
txtemail.Text = email;
txtfirstname.Text = firstname;
txtlastname.Text = lastname;
}
c.Close();
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
c.Open();
String u = "Update tbl_jobreg set
email=@email,firstname=@firstname,lastname=@lastname where
email='(e-mail address removed)'";
SqlCommand co = new SqlCommand(u, c);
co.Parameters.Add(new SqlParameter("@email", SqlDbType.VarChar,
50));
co.Parameters["@email"].Value = txtemail.Text;
co.Parameters.Add(new SqlParameter("@firstname",
SqlDbType.VarChar, 50));
co.Parameters["@firstname"].Value = txtfirstname.Text;
co.Parameters.Add(new SqlParameter("@lastname",
SqlDbType.VarChar, 50));
co.Parameters["@lastname"].Value = txtlastname.Text;
try
{
co.ExecuteNonQuery();
Label1.Text = "Record Updated";
}
catch (SqlException exp)
{
Label1.Text = exp.Message.ToString();
}
c.Close();
}
</script>
what should i change to make it happen alright.
Thanks in advance
nasir
im fetching record from database using datareader, and is displaying
them in the textboxes.
when user change the text fields and then presses the update button the
record should be updated but what happen is: form is postedback but no
change happen to database and also textboxes return to there original
state i.e previous record(enableviewstate is false/same result with
true).
small code is here:
----------------------------------------------------------
<script runat="server">
SqlConnection c = new SqlConnection("user id=sa;password=;Initial
Catalog=jobsdbbackup;Data Source=localhost;Integrated Security=SSPI;");
protected void Page_Load(object sender, EventArgs e)
{
string email = "";
string firstname = "";
string lastname = "";
string strOleDb = "SELECT email,firstname,lastname FROM
tbl_jobreg where email='(e-mail address removed)'";
SqlCommand command = new SqlCommand(strOleDb, c);
c.Open();
SqlDataReader Reader;
Reader = command.ExecuteReader();
while (Reader.Read())
{
email = Reader.GetString(0);
firstname = Reader.GetString(1);
lastname = Reader.GetString(2);
txtemail.Text = email;
txtfirstname.Text = firstname;
txtlastname.Text = lastname;
}
c.Close();
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
c.Open();
String u = "Update tbl_jobreg set
email=@email,firstname=@firstname,lastname=@lastname where
email='(e-mail address removed)'";
SqlCommand co = new SqlCommand(u, c);
co.Parameters.Add(new SqlParameter("@email", SqlDbType.VarChar,
50));
co.Parameters["@email"].Value = txtemail.Text;
co.Parameters.Add(new SqlParameter("@firstname",
SqlDbType.VarChar, 50));
co.Parameters["@firstname"].Value = txtfirstname.Text;
co.Parameters.Add(new SqlParameter("@lastname",
SqlDbType.VarChar, 50));
co.Parameters["@lastname"].Value = txtlastname.Text;
try
{
co.ExecuteNonQuery();
Label1.Text = "Record Updated";
}
catch (SqlException exp)
{
Label1.Text = exp.Message.ToString();
}
c.Close();
}
</script>
what should i change to make it happen alright.
Thanks in advance
nasir