Very first- DataAdapter.Fill method cannot be used with
UPDATE
Command.
The
Fill
method retrieves rows from the data source using the
SELECT
statement specified by an associated
SelectCommand
property. The connection object associated with the
SELECT
statement must be valid, but it does not need to be open. If the connection is closed before
Fill
is called, it is opened to retrieve data, then closed. If the connection is open before Fill is called, it remains open.
You should use
ExecuteNonQuery
to
UPDATE
database.
My_Util util = new My_Util();
util.SetConnection();
util.sql_con.Open();
SqlCommand command = new SqlCommand("update offsale.OS_ToAdvertise set Name ='" + txtContactPer.Text + "',CompanyName='" + txtComname.Text + "',PhoneNo='" + txtPhone.Text + "',ContactBy='" + conbytxtbox.Text + "',City='" + ddlone.Text + "',Area='" + ddltwo.Text + "',Category='" + rdoCate.Text + "',AdvStartDate='" + dstart.ToString("d") + "', AdvEndDate='" + dend.ToString("d") + "',ImagePosition='" + TextBoxposition.Text + "',Imagedimension='" + txtdimension.Text + "'where EMail='" + txtEmail.Text + "'", util.sql_con);
try
{
command.ExecuteNonQuery();
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}