Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.FormatException: Input string was not in a correct format. Source Error: Line 129: ds.Tables["grades"].Rows.Add(dr); Line 130: Line 131: oleDbDataAdapter1.Update(ds,"grades"); Line 132: Line 133: ds.Clear();
هذا هو البرنامج:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
namespace dataset_final
{
/// <summary>
/// Summary description for add.
/// </summary>
public class add : System.Web.UI.Page
{
protected System.Web.UI.WebControls.HyperLink HyperLink5;
protected System.Web.UI.WebControls.HyperLink HyperLink4;
protected System.Web.UI.WebControls.HyperLink HyperLink3;
protected System.Web.UI.WebControls.HyperLink HyperLink2;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.Label Label5;
protected System.Web.UI.WebControls.Label Label6;
protected System.Web.UI.WebControls.Label Label7;
protected System.Web.UI.WebControls.Label Label8;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.TextBox TextBox3;
protected System.Web.UI.WebControls.TextBox TextBox4;
protected System.Web.UI.WebControls.TextBox TextBox5;
protected System.Web.UI.WebControls.TextBox TextBox6;
protected System.Web.UI.WebControls.TextBox TextBox7;
protected System.Web.UI.WebControls.Button Button1;
protected System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
protected System.Data.OleDb.OleDbCommand oleDbInsertCommand1;
protected System.Data.OleDb.OleDbCommand oleDbUpdateCommand1;
protected System.Data.OleDb.OleDbCommand oleDbDeleteCommand1;
protected System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;
protected System.Data.OleDb.OleDbConnection oleDbConnection1;
protected System.Data.OleDb.OleDbCommand oleDbCommand1;
protected System.Web.UI.WebControls.HyperLink HyperLink1;
DataSet ds=new DataSet();
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
oleDbConnection1=new OleDbConnection();
oleDbConnection1.ConnectionString=@"Data Source=""C:\students.mdb"";Provider=""Microsoft.Jet.OLEDB.4.0""";
oleDbCommand1=new OleDbCommand("select * from grades",oleDbConnection1);
oleDbDataAdapter1=new OleDbDataAdapter();
oleDbDataAdapter1.SelectCommand=oleDbCommand1;
OleDbCommand insertCmd=new OleDbCommand("insert into grades (id, fname,lname, first, second, hw, final) values (@id, @fname,@lname, @first, @second, @hw, @final)",oleDbConnection1);
insertCmd.Parameters.Add("@id",OleDbType.VarChar, 12);
insertCmd.Parameters["@id"].Value="id";
insertCmd.Parameters.Add("@fname",OleDbType.VarChar,20);
insertCmd.Parameters["@fname"].Value="fname";
insertCmd.Parameters.Add("@lname",OleDbType.VarChar,20);
insertCmd.Parameters["@lname"].Value="lname";
insertCmd.Parameters.Add("@first",OleDbType.Integer);
insertCmd.Parameters["@first"].Value="first";
insertCmd.Parameters.Add("@second",OleDbType.Integer);
insertCmd.Parameters["@second"].Value="second";
insertCmd.Parameters.Add("@hw",OleDbType.Integer);
insertCmd.Parameters["@hw"].Value="hw";
insertCmd.Parameters.Add("@final",OleDbType.Integer);
insertCmd.Parameters["@final"].Value="final";
oleDbDataAdapter1.InsertCommand=insertCmd;
oleDbDataAdapter1.Fill(ds,"grades");
}
#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.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbInsertCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbUpdateCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbDeleteCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbDataAdapter1 = new System.Data.OleDb.OleDbDataAdapter();
this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
this.oleDbCommand1 = new System.Data.OleDb.OleDbCommand();
this.Button1.Click += new System.EventHandler(this.Button1_Click);
//
// oleDbDataAdapter1
//
this.oleDbDataAdapter1.DeleteCommand = this.oleDbDeleteCommand1;
this.oleDbDataAdapter1.InsertCommand = this.oleDbInsertCommand1;
this.oleDbDataAdapter1.SelectCommand = this.oleDbSelectCommand1;
this.oleDbDataAdapter1.UpdateCommand = this.oleDbUpdateCommand1;
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
DataRow dr=ds.Tables["grades"].NewRow();
dr["id"]=TextBox1.Text;
dr["fname"]=TextBox2.Text;
dr["lname"]=TextBox3.Text;
dr["first"]=Int32.Parse(TextBox4.Text);
dr["second"]=Int32.Parse(TextBox5.Text);
dr["hw"]=Int32.Parse(TextBox6.Text);
dr["final"]=Int32.Parse(TextBox7.Text);
ds.Tables["grades"].Rows.Add(dr);
oleDbDataAdapter1.Update(ds,"grades");
ds.Clear();
oleDbDataAdapter1.Fill(ds,"grades");
// TextBox1.Text="";
// TextBox2.Text="";
// TextBox3.Text="";
// TextBox4.Text="";
// TextBox5.Text="";
// TextBox6.Text="";
// TextBox7.Text="";
}
}
}أرجو الرد السريع للضرورة القصوى
