I need to pass a DataTable to the Oracle DB stored procedure to merge with an existing table, dynamically, from a c# function.
with Microsoft SQL database it's pretty easy, just create a UDT in the database that can match the DataTable column names and then I can use merge in the procedure.
I need to create the user-defined type dynamically and create a merge script dynamically given only the table name, the columns names and type, and the data.
is there a way to do so with Oracle?
I need to do the same with Microsoft SQL database: creating a dynamic user-defined type, using it with a merge procedure that was dynamically created.
just to be clear. the problem is making those merge dynamically, inside the C#.
I do not want to create a new procedure or a user-definded type inside the Oracle or Microsoft SQL databases.
Related
I have a requirement to dynamically create a SQL table based on user uploads of tab delimited files and then insert the contents. I'm using .NET Core / MVC and am able to process the files using the DataTable class, but finding it very awkward to export the .NET DataTable to a (MS) SQL database. I thought there would be some equivalent .NET function of the pandas TO_SQL. Whilst SqlBulkCopy works for inserts into previously defined tables, from what I have read, there is no way to create the table if it does not exist. So my question is, is there a way to create this table dynamically based on the datatable object?
Good Afternoon,
We are currently working on a tool, which retrieves all the Stored Procedures in a given database, which then extracts each Table being used in each Stored Procedure.
Currently, I got all of the Stored Procedures in a List, don't know if there are any parsers available that I can pass the Stored Procedure and returns the Tables being used.
The plan is then to link each Stored Procedure with the Tables being used in a Graph Database.
Thanks
I think there is no prewrited methods to get that. You have to request the database tables, then check in each stored procedure query if it contains the table name.
SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE'
This query will return the tables in the database
Is there any way to pass a complete model to stored procedure using C#?
We can pass parameters to stored procedure but I want to send complete model.
See me answer to other question for complete code sample: SqlBulkCopy Ignore Duplicate Records of Datatable From DataBase
Basically, you can pass a whole datatable. The Merge part is likely not relavent to you.
If you are using SQL Server 2008 or above you can use Table Valued Parameters.
For one of our recent projects, we created a stored procedure which generated SQL and executed it in the end. The purpose of the stored procedure was to create pivots based on dynamic columns.
When trying to access it using Entity Framework using the usual function import when I tried to access the stored procedure, it would return anything as it requires a dynamic type to store the retrieved data.
Which in our case was a dynamic query and linq was unable to get the returned columns. So to work around what I did was call the stored procedure in the traditional way i.e. creating a DataAdapter and SqlCommand object and SqlConnection object.
But what is the proper way of calling this kind of stored procedure using Entity Framework?
Thanks in advance.
Entity framework doesn't support dynamic result sets from stored procedures. It also doesn't support stored procedures using dynamic SQL because it cannot get static result set declaration from the procedure. So you must either ensure that your procedure will always return static type (same number of columns with same names) or you must use traditional ADO.NET to execute that procedure.
Following steps can be followed:
Store the dynamic part of SP inside a variable and the print that variable at end of the SP.
execute the SP and execute it with some data.
open the Messages tab in Result window.
copy the code that is written after (x row(s) affected);
paste that code in the SP and comment out everything else until variables declaration.
execute the new modified SP and add it to the entity framework. This time, entity framework will make a complex type which you want.
uncomment the previous commented code and delete the data that you copied from Messages tab and execute it again.
Follow the same process every time you add or remove columns from the SP.
i want to make Mysql Database converter that can obtain the data from Database A to database B.
both database have same table and column.
how i can make them using c#.
are anyone show me flow or how i can do it
Try the following steps:
Execute the query to retrieve the data from database A;
For every record retrieved, insert a new record into database B.
This mechanism can be automated by automatically creating queries and inserts. To retrieve the tables and fields in a MySQL database, refer to the INFORMATION_SCHEMA tables in MySQL. Using the information retrieved from these tables, you can automatically construct the required queries and migrate an entire database automatically.