Hi,
it shows the following error.Error:Object reference not set to an instance of an object.
public int ExecuteScalar(string Querystring)
{
SqlConnection con = new SqlConnection("data source=mars-104;initial catalog=Sudheeptest;integrated security=true");
SqlCommand cmd = new SqlCommand(Querystring, con);
con.Open();
SqlDataAdapter adp = new SqlDataAdapter(cmd);
return (int)cmd.ExecuteScalar();//error:Object reference not set to an instance of an object.
}
private void btnupdate_Click(object sender, EventArgs e)
{
string querystring = string.Empty;
if (!Validation())
return;
if (txtNewpassword.Text.Trim() != txtreenternewpassword.Text.Trim())
{
MessageBox.Show("Re-Entered Password does match with new password", "Information", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
querystring ="update tbl_login set username='" +txtusername .Text .Trim ()+"' where password='"+txtoldpassword .Text .Trim ()+"'";
int count= ExecuteScalar(querystring );
if (count > 0)
{
querystring ="update tbl_login set password='" +txtNewpassword .Text .Trim ()+"' where username='" +txtusername .Text .Trim ()+"'";
MessageBox .Show ("Password has been changed successfully","Information",MessageBoxButtons .OK ,MessageBoxIcon.Information );
}
}
}
Best,
Sudheep.