asked on
public DataSet UpdateBook(String baddress, String bpostalcode, String bcountry, String saddress, String spostalcode, String scountry, String bcompany, String bcity, String scompany, String scity)
{
int result = 0;
DataSet updateAdd;
SqlDataAdapter da;
string queryStr = "UPDATE CompanyAddress"
+ "SET BillingAddress=@billingaddress, BillingPostalCode=@billingpostalcode, BillingCountry=@billingcountry, ShippingAddress=@shippingaddress, ShippingPostalCode=@shippingpostalcode, ShippingCountry=@scountry, BillingCompany=@billingcompany, BillingCity=@billingcity, ShippingCompany=@shippingcompany, ShippingCity=@shippingcity"
+ "WHERE CompAddressId=@compAddressId";
SqlConnection conn = new SqlConnection(_connStr);
updateAdd = new DataSet();
SqlCommand cmd = new SqlCommand(queryStr, conn);
try
{
da = new SqlDataAdapter(queryStr.ToString(), conn);
da.Fill(updateAdd);
cmd.Parameters.AddWithValue("@billingaddress", baddress);
cmd.Parameters.AddWithValue("@billingpostalcode", bpostalcode);
cmd.Parameters.AddWithValue("@billingcountry", bcountry);
cmd.Parameters.AddWithValue("@shippingaddress", saddress);
cmd.Parameters.AddWithValue("@shippingpostalcode", spostalcode);
cmd.Parameters.AddWithValue("@scountry", scountry);
cmd.Parameters.AddWithValue("@billingcompany", bcompany);
cmd.Parameters.AddWithValue("@billingcity", bcity);
cmd.Parameters.AddWithValue("@shippingcompany", scompany);
cmd.Parameters.AddWithValue("@shippingcity", scity);
result = cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
errMsg = ex.Message;
}
finally
{
conn.Close();
}
return updateAdd;
}
And the code behind for project A protected void btnUpdateAddress_Click(object sender, EventArgs e)
{
BllCompAddressBook updateAdd = new BllCompAddressBook();
int result = 0;
if (result == 0)
{
DataSet ds = updateAdd.UpdateBookList(tb_bAddress.Text, tb_bPostalCode.Text, tb_bCountry.Text, tb_sAddress.Text, tb_sPostalCode.Text, tb_sCountry.Text, tb_bCompany.Text, tb_bCity.Text, tb_sCompany.Text, tb_sCity.Text);
Response.Write("<script>alert('Update successful');</script>");
}
else
{
Response.Write("<script>alert('Update NOT successful.');</script>");
}
}
Any idea why??
ASKER
public int UpdateBook(int addressid, String baddress, String bpostalcode, String bcountry, String saddress, String spostalcode, String scountry, String bcompany, String bcity, String scompany, String scity)
{
StringBuilder sql;
SqlCommand sqlCmd;
int result;
result = 0;
sql = new StringBuilder();
sql.AppendLine("UPDATE CompanyAddress");
sql.AppendLine(" ");
sql.AppendLine("SET BillingAddress=@billingaddress, BillingPostalCode=@billingpostalcode, BillingCountry=@billingcountry, ShippingAddress=@shippingaddress, ShippingPostalCode=@shippingpostalcode, ShippingCountry=@scountry, BillingCompany=@billingcompany, BillingCity=@billingcity, ShippingCompany=@shippingcompany, ShippingCity=@shippingcity");
sql.AppendLine(" ");
sql.AppendLine("WHERE CompAddressId=@compAddressId");
SqlConnection conn = dbConn.GetConnection();
try
{
sqlCmd = new SqlCommand(sql.ToString(), conn);
sqlCmd.Parameters.AddWithValue("@compAddressId", addressid);
sqlCmd.Parameters.AddWithValue("@billingaddress", baddress);
sqlCmd.Parameters.AddWithValue("@billingpostalcode", bpostalcode);
sqlCmd.Parameters.AddWithValue("@billingcountry", bcountry);
sqlCmd.Parameters.AddWithValue("@shippingaddress", saddress);
sqlCmd.Parameters.AddWithValue("@shippingpostalcode", spostalcode);
sqlCmd.Parameters.AddWithValue("@scountry", scountry);
sqlCmd.Parameters.AddWithValue("@billingcompany", bcompany);
sqlCmd.Parameters.AddWithValue("@billingcity", bcity);
sqlCmd.Parameters.AddWithValue("@shippingcompany", scompany);
sqlCmd.Parameters.AddWithValue("@shippingcity", scity);
result = sqlCmd.ExecuteNonQuery();
}
catch (Exception ex)
{
errMsg = ex.Message;
}
finally
{
conn.Close();
}
return result;
}
protected void btnUpdateAddress_Click(object sender, EventArgs e)
{
BllCompAddressBook updateAdd = new BllCompAddressBook();
int result = 0;
if (result == 0) {
updateAdd.UpdateBookList(int.Parse(lblId.Text), tb_bAddress.Text, tb_bPostalCode.Text, tb_bCountry.Text, tb_sAddress.Text, tb_sPostalCode.Text, tb_sCountry.Text, tb_bCompany.Text, tb_bCity.Text, tb_sCompany.Text, tb_sCity.Text);
Response.Write("<script>alert('Update successful');</script>");
}
//else
//{
// Response.Write("<script>alert('Update NOT successful.');</script>");
//}
}
Reason why i have updateboklist is that im using webservice !! so in the BLL folder i have DalCompAddressBook Address = new DalCompAddressBook();
public int UpdateBookList(int caddressid, string baddress, string bpostalcode, string bcountry, string saddress, string spostalcode, string scountry, string bcompany, string bcity, string scompany, string scity)
{
return Address.UpdateBook(caddressid, baddress, bpostalcode, bcountry, saddress, spostalcode, scountry, bcompany, bcity, scompany, scity);
}
i changed the Update to this but nothing workedwhat's the error now?
ASKER
ASKER
ASKER
The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications
TRUSTED BY
ASKER
Open in new window
I did that, but my project A has an error!!there are red lines at UpdateBookList(1); part
I dont have a textbox id, so i did it like:
Open in new window
The error is : There is no argument given that corresponds to the required formal parameter 'baddress' of 'BllCompAddressBook.Update