我有一个名为 fillgrid() 的函数,它用数据填充网格。但是在我调用将记录插入数据库的 insert() 函数后,它没有被执行。
它在我的本地系统中工作正常。但是当我发布我的解决方案并将其放入服务器时,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;
}