0
我有一個名爲fillgrid()的函數,它用data填充網格,但是在調用插入記錄到數據庫中的insert()函數後,它不會執行。將記錄插入到數據庫中後,PageRefresh不起作用
它在我的本地system.But工作正常,但當我發佈我的解決方案,並將其放入服務器fillgrid()函數沒有得到執行。我沒有得到任何錯誤,我不明白爲什麼fillgrid()函數沒有得到所謂?
這是我的代碼插入功能。
DataTable dtMob = new DataTable();
dtMob = dtMobilizn.Copy();
DataSet dsMobilizn=new DataSet("dsMobilization");
dsMobilizn.Tables.Add(dtMob);
int i = clsMob.InsertMobilizationDetails(dsMobilizn.GetXml());//i am getting the value as 1 when i debugged in local system
if (i != -1)
{
FillGrid();//This function is not getting called.
}
else
{
string str = "<script>alert('Cannot mobilize')</script>";
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Validation Error", str, false);
return;
}
這是填充網格函數的代碼。該函數在頁面加載時調用,並且正常工作。
DataTable dtGrid = clsMob.GetStandByEmployee(txtSrchEmpCode.Text.Trim());
if (dtGrid.Rows.Count > 0)
{
if (ViewState["Sort"] != null)
{
DataView dView = new DataView(dtGrid);
dView.Sort = ViewState["Sort"].ToString();
gdMobilizn.DataSource = dView;
gdMobilizn.DataBind();
}
else
{
gdMobilizn.DataSource = dtGrid;
gdMobilizn.DataBind();
}
}
else
{
gdMobilizn.DataSource = null;
gdMobilizn.EmptyDataText = "No Standby Employees Found";
gdMobilizn.DataBind();
}
這是InsertMobilizationDetails
public int InsertMobilizationDetails(string xml)
{
Database_Operations dbo = new Database_Operations("TransMob_InDetails", true);
dbo.AddParameter("@xmlMob", xml);
return dbo.ExecuteQuery();
}
的功能,這是的executeQuery
public int ExecuteQuery()
{
int rowsAffected = -1;
SqlCon = new SqlConnection();
using (SqlCon = new SqlConnection(ConfigurationManager.ConnectionStrings["SQL_CONNECTION"].ToString()))
{
try
{
SqlCon.Open();
SqlCmd.Connection = SqlCon;
SqlTransaction transaction;
transaction = SqlCon.BeginTransaction();
try
{
SqlCmd.Transaction = transaction;
rowsAffected = SqlCmd.ExecuteNonQuery();
transaction.Commit();
rowsAffected = 1;
}
catch (Exception ex)
{
transaction.Rollback();
rowsAffected = -1;
//Response.Write(ex.Message);
}
}
catch (Exception exp)
{
rowsAffected = -1;
//Response.Write(exp.Message);
}
finally
{
SqlCon.Close();
SqlCon.Dispose();
}
}
return rowsAffected;
}
由於我們無法看到InsertMobilizationDetails函數的作用,所以我們無法診斷... –
clsMob.InsertMobilizationDetails(dsMobilizn.GetXml())的後置代碼; – iJade
如果(i!= -1)看到我的價值是多少,你有沒有在 旁邊放置一個斷點? -1代表什麼?沒有添加? 另外,你有沒有步入 clsMob.InsertMobilizationDetails(dsMobilizn.GetXml());看看這是否給出了預期的結果? – christiandev