faramarz_s
چهارشنبه 02 مهر 1382, 11:16 صبح
http://shahabedeen.europe.webmatrixhosting.net/1.gif
مشکل از چه قرار است:
1-فایروالی ندارم.
2-تا چندی قبل کار میکرد.
3-با تغییرنام صفحه همین پیغام را می داد:
متن برنامه این صفحه:
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if(!Page.IsPostBack)
bindToDatGrid();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.DataGrid1.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHand ler(this.DataGrid1_CancelCommand);
this.DataGrid1.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHand ler(this.DataGrid1_EditCommand_1);
this.DataGrid1.DataBinding += new System.EventHandler(this.Page_Load);
this.DataGrid1.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHand ler(this.DataGrid1_UpdateCommand_1);
this.DataGrid1.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHand ler(this.DataGrid1_DeleteCommand);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
//------------------------------------------------------------------------------------------------
void bindToDatGrid()
{
SqlConnection cnn = new
SqlConnection("server=(local);uid=sa;pwd=yaali;database=MDB" );
SqlDataAdapter dtAdap = new
SqlDataAdapter("select * from tblPrimary",cnn);
DataSet dsetSales = new DataSet();
dtAdap.Fill(dsetSales, "tblPrimary");
DataGrid1.DataSource = dsetSales.Tables["tblPrimary"].DefaultView;
DataGrid1.DataBind();
}
//------------------------------------------------------------------------------------------------
private void DataGrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex = -1;
bindToDatGrid();
}
//------------------------------------------------------------------------------------------------
private void DataGrid1_UpdateCommand_1(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string id = ((TextBox)e.Item.Cells[1].Controls[0]).Text;
string un = ((TextBox)e.Item.Cells[2].Controls[0]).Text;
string uf = ((TextBox)e.Item.Cells[3].Controls[0]).Text;
string password = ((TextBox)e.Item.Cells[4].Controls[0]).Text;
string email = ((TextBox)e.Item.Cells[5].Controls[0]).Text;
SqlConnection conn =
new SqlConnection("server=(local);uid=sa;pwd=yaali;database=MDB;");
// Prepare the command text
String strCmd = "UPDATE tblPrimary SET un='"+
un+ "'," + "uf='" + uf+ "'"+
" WHERE id='" + id+"'";
SqlCommand cmd = new SqlCommand(strCmd, conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
// Reset the edit mode for the current item
DataGrid1.EditItemIndex = -1;
// create data source again.........
bindToDatGrid();
}
//------------------------------------------------------------------------------------------------
private void DataGrid1_EditCommand_1(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex = e.Item.ItemIndex;
bindToDatGrid();
}
//------------------------------------------------------------------------------------------------
private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string id = ((TextBox)e.Item.Cells[1].Controls[0]).Text;
string un = ((TextBox)e.Item.Cells[2].Controls[0]).Text;
string uf = ((TextBox)e.Item.Cells[3].Controls[0]).Text;
string password = ((TextBox)e.Item.Cells[4].Controls[0]).Text;
string email = ((TextBox)e.Item.Cells[5].Controls[0]).Text;
SqlConnection conn =
new SqlConnection("server=(local);uid=sa;pwd=yaali;database=MDB;");
// Prepare the command text
//String strCmd = "DELETE FROM tblPrimary "+
// " WHERE id='" +id + "'";
String strCmd = "DELETE FROM tblPrimary WHERE id = @Id";
SqlCommand myCommand = new SqlCommand(strCmd, conn);
myCommand.Parameters.Add(new SqlParameter("@Id",
SqlDbType.Int, 4));
// Initialize the SqlCommand "@Id" parameter to the ID of the row
// that was clicked.
myCommand.Parameters["@Id"].Value =
DataGrid1.DataKeys[(int)e.Item.ItemIndex];
SqlCommand cmd = new SqlCommand(strCmd, conn);
conn.Open();
try
{
cmd.ExecuteNonQuery();
Label2.Text= "<b>Record Deleted</b><br>";
}
catch (SqlException)
{
Label2.Text= "ERROR: Could not delete record";
}
conn.Close();
// Reset the edit mode for the current item
DataGrid1.EditItemIndex = -1;
// create data source again.........
bindToDatGrid();
}
مشکل از چه قرار است:
1-فایروالی ندارم.
2-تا چندی قبل کار میکرد.
3-با تغییرنام صفحه همین پیغام را می داد:
متن برنامه این صفحه:
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if(!Page.IsPostBack)
bindToDatGrid();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.DataGrid1.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHand ler(this.DataGrid1_CancelCommand);
this.DataGrid1.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHand ler(this.DataGrid1_EditCommand_1);
this.DataGrid1.DataBinding += new System.EventHandler(this.Page_Load);
this.DataGrid1.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHand ler(this.DataGrid1_UpdateCommand_1);
this.DataGrid1.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHand ler(this.DataGrid1_DeleteCommand);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
//------------------------------------------------------------------------------------------------
void bindToDatGrid()
{
SqlConnection cnn = new
SqlConnection("server=(local);uid=sa;pwd=yaali;database=MDB" );
SqlDataAdapter dtAdap = new
SqlDataAdapter("select * from tblPrimary",cnn);
DataSet dsetSales = new DataSet();
dtAdap.Fill(dsetSales, "tblPrimary");
DataGrid1.DataSource = dsetSales.Tables["tblPrimary"].DefaultView;
DataGrid1.DataBind();
}
//------------------------------------------------------------------------------------------------
private void DataGrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex = -1;
bindToDatGrid();
}
//------------------------------------------------------------------------------------------------
private void DataGrid1_UpdateCommand_1(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string id = ((TextBox)e.Item.Cells[1].Controls[0]).Text;
string un = ((TextBox)e.Item.Cells[2].Controls[0]).Text;
string uf = ((TextBox)e.Item.Cells[3].Controls[0]).Text;
string password = ((TextBox)e.Item.Cells[4].Controls[0]).Text;
string email = ((TextBox)e.Item.Cells[5].Controls[0]).Text;
SqlConnection conn =
new SqlConnection("server=(local);uid=sa;pwd=yaali;database=MDB;");
// Prepare the command text
String strCmd = "UPDATE tblPrimary SET un='"+
un+ "'," + "uf='" + uf+ "'"+
" WHERE id='" + id+"'";
SqlCommand cmd = new SqlCommand(strCmd, conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
// Reset the edit mode for the current item
DataGrid1.EditItemIndex = -1;
// create data source again.........
bindToDatGrid();
}
//------------------------------------------------------------------------------------------------
private void DataGrid1_EditCommand_1(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex = e.Item.ItemIndex;
bindToDatGrid();
}
//------------------------------------------------------------------------------------------------
private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string id = ((TextBox)e.Item.Cells[1].Controls[0]).Text;
string un = ((TextBox)e.Item.Cells[2].Controls[0]).Text;
string uf = ((TextBox)e.Item.Cells[3].Controls[0]).Text;
string password = ((TextBox)e.Item.Cells[4].Controls[0]).Text;
string email = ((TextBox)e.Item.Cells[5].Controls[0]).Text;
SqlConnection conn =
new SqlConnection("server=(local);uid=sa;pwd=yaali;database=MDB;");
// Prepare the command text
//String strCmd = "DELETE FROM tblPrimary "+
// " WHERE id='" +id + "'";
String strCmd = "DELETE FROM tblPrimary WHERE id = @Id";
SqlCommand myCommand = new SqlCommand(strCmd, conn);
myCommand.Parameters.Add(new SqlParameter("@Id",
SqlDbType.Int, 4));
// Initialize the SqlCommand "@Id" parameter to the ID of the row
// that was clicked.
myCommand.Parameters["@Id"].Value =
DataGrid1.DataKeys[(int)e.Item.ItemIndex];
SqlCommand cmd = new SqlCommand(strCmd, conn);
conn.Open();
try
{
cmd.ExecuteNonQuery();
Label2.Text= "<b>Record Deleted</b><br>";
}
catch (SqlException)
{
Label2.Text= "ERROR: Could not delete record";
}
conn.Close();
// Reset the edit mode for the current item
DataGrid1.EditItemIndex = -1;
// create data source again.........
bindToDatGrid();
}