Govind Sankar
Active member
- Joined
- May 15, 2020
- Messages
- 42
- Programming Experience
- Beginner
I have a database and then a dataset in C# Visual Studio. In the database there is a table with a column called CardType. This was created by someone before me. And the value in this column is always 40. So he created it of type double.
I was told now that now the value has to be changed to SAR40 and not just 40. So now it is a string. So when I changed the value to SAR40 obviously there will be error when trying to add SAR40 to a column of type double. So first I went to SQL Server Management Studio and changed the type to nvarchar there. Then I come back to Visual Studio and changed the type of datatype of CardType to System.String.
Then when I run the program I still get an error
workRow["CardType"] = type.Text; // CardType is string, I double checked by hovering the mouse over it and it shows as string.
workRow["Hardwarerevision"] = hw.Text;
Then we add the datarow into the dataset.
//add new data row
ds.UNIO_CPU.Rows.Add(workRow);
Finally we update the database using the dataset using a table adapter called DataGridAdapter_CPU
//write data to database
DataGridAdapter_CPU.Update(workRow);
So why do I still get an error?
I try to run the program with just 40 and the program is showing no error. It works fine. How is that possible. Because I changed both in the SQL Server Management Studio and dataset in Visual Studio to string type. So here it should show error. But it is not showing error. Whereas I try to enter SAR40 then it is showing error that you cant convert string to double.
The error is happening in the line DataGridAdapter_CPU.Update(workRow). Because i commented out this line and ran the rest. There was no error and the program worked but since this line was commented out, the database didnt recieve the new row. So the error happens when the tableadapter tries to add the datarow into the sql server database. But as I said I have changed CardType in the dataset to System.string and then also the colum CardType in SSMS to string. So is there something in the tableadapter I have to change. I am not an expert in this, I only know basic c# programming. Kindly do help me. Thank You.
I was told now that now the value has to be changed to SAR40 and not just 40. So now it is a string. So when I changed the value to SAR40 obviously there will be error when trying to add SAR40 to a column of type double. So first I went to SQL Server Management Studio and changed the type to nvarchar there. Then I come back to Visual Studio and changed the type of datatype of CardType to System.String.
Then when I run the program I still get an error
How the program works is there are a bunch of small sections to fill data and each of the data goes into the database. Data like cardtype, hardwarerevision etc. So we create a datarow called workrow and then add this into the workrow.Parameter value could not be converted from string to double.
FormatException: The input string is in the wrong format.
workRow["CardType"] = type.Text; // CardType is string, I double checked by hovering the mouse over it and it shows as string.
workRow["Hardwarerevision"] = hw.Text;
Then we add the datarow into the dataset.
//add new data row
ds.UNIO_CPU.Rows.Add(workRow);
Finally we update the database using the dataset using a table adapter called DataGridAdapter_CPU
//write data to database
DataGridAdapter_CPU.Update(workRow);
So why do I still get an error?
I try to run the program with just 40 and the program is showing no error. It works fine. How is that possible. Because I changed both in the SQL Server Management Studio and dataset in Visual Studio to string type. So here it should show error. But it is not showing error. Whereas I try to enter SAR40 then it is showing error that you cant convert string to double.
The error is happening in the line DataGridAdapter_CPU.Update(workRow). Because i commented out this line and ran the rest. There was no error and the program worked but since this line was commented out, the database didnt recieve the new row. So the error happens when the tableadapter tries to add the datarow into the sql server database. But as I said I have changed CardType in the dataset to System.string and then also the colum CardType in SSMS to string. So is there something in the tableadapter I have to change. I am not an expert in this, I only know basic c# programming. Kindly do help me. Thank You.