I am using tableadpters and datasets generated by wizards to connect a DataGridView to a source.
I changed databases for the application, but I am getting an error for the stored procedures that still have the "OldDb.dbo.sp_GetWorkbarTypes" on them. I did a search for the "OldDb" and changed everything to "NewDb" but I till get a connection error saying that it cannot find "OldDb.dbo.sp_GetWorkbarTypes".
How do I change the adapters to point to the new Database?
this.sp_GetWorkbarTypesTableAdapter.Fill(this.workBarTypesDataSet.sp_GetWorkbarTypes);
throws a
Invalid object name Invalid object name
where the heck is this getting this string from? I changed them in the find
Related
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
Parameter value could not be converted from string to double.
FormatException: The input string is in the wrong format.
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. And from this it will form a workrow.
workRow["CardType"] = type.Text;
workRow["Hardwarerevision"] = hw.Text;
and then finally add to the database using these two lines
//add new data row
ds.UNIO_CPU.Rows.Add(workRow);
//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. What could be the error reason? Kindly help me. Thank you.
It is not clear what are the nature of the objects from your post. Also, it is not obvious where exception happens. From your sample, is it OK on string
ds.UNIO_CPU.Rows.Add(workRow);
And fails on
DataGridAdapter_CPU.Update(workRow);
Right?
And can you provide more details about DataGridAdapter_CPU?
In addition, DataSet contains DataTable with its own structure, did you check it?
This article Connecting to PowerPivot with C# is the closest to my question but it seems that it is out of date. I attempted the methods they showed in the answer but the example
ThisWorkbook.Connections["PowerPivot Data"].OLEDBConnection.ADOConnection
Does not return the connection information, rather an exception.
But I was able to access the PP Data Model using:
ThisAddIn.Current.Application.ActiveWorkbook.Connections[1]. ModelTables[1].ModelTableColumns[1].Name`
But the object only allows you to look at the column names in the model. I wasn't able to get the connection information or anything.
ThisAddIn.Current.Application.ActiveWorkbook.Connections[1].ModelConnection.ADOConnection`
causes an exception and so does:
ThisAddIn.Current.Application.ActiveWorkbook.Connections[1].OLEDBConnection.ADOConnection
MY QUESTIONS
Have I made a mistake in my code?
Is there another method to connect to the datamodel that I haven't listed above?
Is it possible to read the records in the datamodel? (I was able to read column names)
Thank you for your time!
string ConnString = "Provider=MSOLAP;Data Source=$Embedded$;
Locale Identifier=1033;Location=" + ThisAddIn.Current.Application.ActiveWorkbook.FullName + ";SQLQueryMode=DataKeys";
Microsoft.AnalysisServices.Server OlapServer = new Microsoft.AnalysisServices.Server();
OlapServer.Connect(ConnString);
I'm using an SQL Server 2008 database which contains an Geometry column and I'm now having problems loading and manipulating that data in CSharp when it hasn't been a problem before.
I have an object which is of the Microsoft.SqlServer.Types.SqlGeometry type and I need to get the STNumGeometries i.e.:
var numberOfGeometries = tmpDelytas[i].Delyta.DelytaGrans.STNumGeometries();
but it is causing an error:
ArgumentException 24144: This operation cannot be completed because the instance is not valid. Use MakeValid to convert the instance to a valid instance. Note that MakeValid may cause the points of a geometry instance to shift slightly.
I checked the Geometry value in SQLServer and STIsValid there reports that is is valid. (Unsurprising as the code has previously worked).
The geometry is valid according to STIsValid both in CSharp and in SQLServer, and STNumGeometries works in the database and if I put a breakpoint there then the value of STNumGeometries is reported as 1 in the watch. But still the program crashes with this error if I step forward.
Why might my code be suddenly unwilling to process the line of code?
Update
I've found a "solution", but would still like to understand the problem because this stinks...
var geomText = tmpDelytas[0].Delyta.DelytaGrans.ToString();
var geom = SqlGeometry.STGeomFromText(new SqlChars(geomText),0);
var numberOfGeometries = geom.STNumGeometries();
And this works.
I'm trying to work with SQLITE in .
However I've faced a weird problem :
// Start of code
connection = new SQLiteConnection(myConnectionString);
connection.Open();
myDataContext = new Main(connection, new SqliteVendor());
// End of code
Examing 'myDataContext' after execution (with debugger), I see it has the type 'Main' (as should be :)) and also has as members,
the names of the tables I've defind in DB (so far - so good...), but...
Trying open one table (which has(!) records), and then trying to open the "ResultView" member of that table, I'm facing the string
"SQLite error\n No such table: main:XXXX"
(XXXX is the table name...)
(I've came to examine the structure because when I've tried to fetch records by linq command - I've got an exception.)
Do you have any idea what can cause this behavior?
Thanks,
Rivka
Ok, I've found the source of it...
(actually found it several hours after I've published the question...)
I'm working with visual studio and my DB file name is part of the project.
Since I've changed the (name and content...) of th db filename, i've forgot to mark
it "Copy Always"... That has caused the problem.
Please mark that as solved...
I have a MySQL query I'm running from C#. I use the MySqlDataAdapter to fill a DataTable. However I am getting the following exception:
MySql.Data.Types.MySqlConversionException: Unable to convert MySQL date/time value to System.DateTime
I can't really modify the query (it's loaded from an external source). And I'm hoping I don't have to manually fill the data table. Anyone had this before?
I should also add I have tried adding allow zero datetime=no to the connection string with no success.
I think you made a mistake with your addition to the connection string! It should be:
Allow Zero Datetime = true