C# Windows application database insert problem
[font=Arial]Hi experts
I created a C# windows application linked to DataBase.But I met a problem when trying to convert string to single variable[format like this: 3.5]..
The statement is contained in Event:
private void buttonSubmit_Click(object sender, EventArgs e)
{
NumberFormatInfo provider = new NumberFormatInfo();
provider.PercentDecimalDigits = 1;
DataRow newRow = studentDataSet.Tables["BasicInfo"].NewRow();
newRow["StuNO"] = textBoxStudentNO.Text;
newRow["StuName"] = textBoxStudentName.Text;
newRow["GP"] = Convert.ToSingle(textBoxGradePoint.Text,provider);
newRow["MIS"] = Convert.ToInt32(textBoxMIS.Text);
newRow["DB"] = Convert.ToInt32(textBoxDatabase.Text);
newRow["FM"] = Convert.ToInt32(textBoxFinanceManagement.Text);
newRow["EM"] = Convert.ToInt32(textBoxEnterpriseManagement.Text);
studentDataSet.Tables["BasicInfo"].Rows.Add(newRow);
//this.basicInfoBindingSource.EndEdit();
this.basicInfoTableAdapter.Update(
this.studentDataSet.BasicInfo);
buttonModify.Enabled = true;
buttonNew.Enabled = true;
}
When I fill "textBoxGradePoint" with "2.4" for example. and click "submit" button to insert. The corresponding value in Database was changed to "2.400000095367432"...why? It seems the patameter "provider" passed to Convert.toSingle doesn't work at all.How could I stop the value being changed after inserted into databse?
Another stange thing is that whenever I try to insert a row into table "BasicInfo". An exception will be thrown saying "Column "StuNO" is constrained to be unique,Value is already present"...I promise there is no violation about primary key. to prove that,I even inserted another completely different value of primary key but the exception still came out.It's confusing the row was still inderted successfully when I checked the DB.
I dragged a ListBox control where all StuNo will be shown.when I fill all textBoxs with values and then click "submit" button. Exception mentioned above came out and the "StuNO" in textBoxStudentNO will be added to ListBox TWICE!
please help me out,great appreciation!
ERIC
__________________
ERIC
|