Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 27th, 2007, 01:44 AM
Authorized User
 
Join Date: Mar 2007
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to erictamlam Send a message via MSN to erictamlam Send a message via Yahoo to erictamlam
Default 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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Web Application OR Windows Application adesilva .NET Framework 2.0 2 May 4th, 2007 07:12 AM
Problem with creating EXE for Windows Application ssampath VS.NET 2002/2003 0 May 18th, 2006 05:51 AM
Database Insert/Update problem with VB.NET form tino mclaren VB Databases Basics 2 February 4th, 2005 05:12 AM
Web application Vs Windows Application Ned .NET Web Services 2 January 20th, 2004 01:27 PM
Database access from java, INSERT query problem nitusincog BOOK: Beginning Java 2 1 July 21st, 2003 10:26 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.