Please any one who can help me i will be very thank full to him Please help me for this error to solve I am new in C# So please Consider my Question It is big but. your few minutes can solve my Problem and i will pray him tell death So please please help
I have record in my Database which have following Datatype as
StudentID=INT,
FirstName=VarChar,
LastName=VarChar,
Gender=Varchar,
GPA=Float,
MyImage=Vabinary (MAX)
This is my Database type but i add the Datatype in in my Parameter to inserting and Updating is not corrupt i thing please check that is my Datatype is correct for Adding parameter the SqlDataAdapter
Then I add the Parameter for these type for inserting Updating Deleting record as
SqlDataAdapter dataAdapter = new SqlDataAdapter();
dataAdapter.SelectCommand =newSqlCommand(gettSQL,ConnectionManager.GetConnection());
dataAdapter.InsertCommand=newSqlCommand(insertSQL,ConnectionManager.GetConnection());
dataAdapter.InsertCommand.Parameters.Add
("@StudentID",SqlDbType.Int).SourceColumn="StudentID";
dataAdapter.InsertCommand.Parameters.Add
("@FirstName",SqlDbType.VarChar,25).SourceColumn="FirstName";
dataAdapter.InsertCommand.Parameters.Add
("@LastName",SqlDbType.VarChar,25).SourceColumn="LastName";
dataAdapter.InsertCommand.Parameters.Add("@Gender",SqlDbType.VarChar,1).SourceColumn="Gender";
dataAdapter.InsertCommand.Parameters.Add
("@GPA",SqlDbType.Float).SourceColumn="GPA";
dataAdapter.InsertCommand.Parameters.Add
("@MyImage",SqlDbType.VarBinary).SourceColumn="MyImage";
//Create the UpdateCommand and the Parameters
dataAdapter.UpdateCommand=newSqlCommand(updateSQL,ConnectionManager.GetConnection());
dataAdapter.UpdateCommand.Parameters.Add
("@StudentID",SqlDbType.Int).SourceColumn="StudentID";
dataAdapter.UpdateCommand.Parameters.Add
("@FirstName",SqlDbType.VarChar,25).SourceColumn="FirstName";
dataAdapter.UpdateCommand.Parameters.Add
("@LastName",SqlDbType.VarChar,25).SourceColumn="LastName";
dataAdapter.UpdateCommand.Parameters.Add
("@Gender",SqlDbType.VarChar,1).SourceColumn="Gender";
dataAdapter.UpdateCommand.Parameters.Add
("@GPA", SqlDbType.Float ).SourceColumn="GPA";
dataAdapter.UpdateCommand.Parameters.Add
("@MyImage",SqlDbType.VarBinary).SourceColumn="MyImage";
dataAdapter.DeleteCommand=newSqlCommand(deleteSQL,ConnectionManager.GetConnection());
dataAdapter.DeleteCommand.Parameters.Add
("@StudentID",SqlDbType.Int).SourceColumn="StudentID";
return dataAdapter;
And TableSchima for the Student Table Also Watch is Datatype is wrong are right
DataColumn StudentIDColumn = table.Columns.Add("StudentID",typeof(string));
StudentIDColumn.AllowDBNull = false;
table.PrimaryKey = new DataColumn[] { StudentIDColumn };
DataColumn StudentFirstName = table.Columns.Add("FirstName",typeof(string));
StudentFirstName.MaxLength = 150;
DataColumn StudentLastName = table.Columns.Add("LastName",typeof(string));
StudentLastName.MaxLength = 150;
DataColumn StudentGender = table.Columns.Add("Gender",typeof(string ));
DataColumn StudentGPA = table.Columns.Add("GPA", typeof(Char));
DataColumn StudentImage = table.Columns.Add("MyImage", typeof(Byte[]));
And DataSet for the Student is Consider is constraint is right to false and true also
private static DataSet CreateStudentTrackerDataSet()
{DataSet StudentTrackerDataSet = new DataSet();
DataTable StudentTable = StudentTrackerDataSet.Tables.Add("Student");
DefinestudentTableSchema(StudentTable);
return StudentTrackerDataSet;}
//GetDataFunction that Populat the Gridview
public static DataSet GetData()
DataSet StudentTrakerDataSet = CreateStudentTrackerDataSet();
StudentTrakerDataSet.EnforceConstraints = false;
StudentDataAdapter.Fill(StudentTrakerDataSet.Tables["Student"]);
StudentTrakerDataSet.EnforceConstraints = true;
return StudentTrakerDataSet;
And my SaveDatamethode is
DataSet addedDataSet = changesDataSet.GetChanges(DataRowState.Added);
if (addedDataSet != null)
{
StudentDataAdapter.Update(addedDataSet.Tables["Student"]);
changesDataSet.Merge(addedDataSet);
}
DataSet modifiedDataSet = changesDataSet.GetChanges(DataRowState.Modified);
if (modifiedDataSet != null)
{
StudentDataAdapter.Update(modifiedDataSet.Tables["Student"]);
changesDataSet.Merge(modifiedDataSet);
}
DataSet deletedDataSet = changesDataSet.GetChanges(DataRowState.Deleted);
if (deletedDataSet != null)
{
StudentDataAdapter.Update(deletedDataSet.Tables["Student"]);
deletedDataSet.Merge(deletedDataSet);
Button that will Add the Student Record in Datarow of Dataset is or you can say to Grid is Here i take a mistake I sure About it for Datatype So tell me where i take the Mistake Because My whole program is right but for the error above is due to the Data is not updated correctly in Datarow So Consider and tell me where i take the Mistake for the Datatype
private void button2_Click(object sender, EventArgs e)
{ string StudentID = textBox1.Text.ToString();
string StudentFirstName = textBox2.Text.ToString();
string StudentLastName = textBox4.Text.ToString();
string Gender = textBox3.Text.ToString();
string GPA = textBox5.Text.ToString();
Image MyImage = pictureBox1.Image;
DataTable table = StudentTrackerDataSet.Tables["Student"];
if (currentRow == null)
{
currentRow = table.NewRow();
currentRow["StudentID"] = textBox1.Text.ToString();
table.Rows.Add(currentRow );
}
currentRow .BeginEdit();
currentRow ["StudentID" ]=StudentID ;
currentRow["FirstName"] = StudentFirstName;
currentRow["LastName"] = StudentLastName;
currentRow["Gender"] = Gender;
currentRow["GPA"] = GPA;
currentRow["MyImage"] = convertToByte(txtBrowseFile.Text);
currentRow.EndEdit();
Close();}
Please any one who can help me i will be very thank full to him Please help me for this error to solve I am new in C# So please Consider my Question It is big but. your few minutes can solve my Problem and i will pray him tell death So please please help NOTE:- When i press the save button then Data is also overlapes means last when copy to whole other record Means if last is record have Fristname Raju then whole other record when i press the save button it will be Raju so Please please tell me how to fix it