ado.net

Async odbc seems to be synchronous

不羁岁月 提交于 2021-02-07 18:43:24
问题 I'm trying to do async database queries, but when I test my code it appears to be synchronous. I've isolated the issue to my Query function. Can't figure out what I'm doing wrong, I'm pretty new to the aync/await functionality so it's possible that I've done something stupid :) This is the failing code: (i'm using a local install of postgresql) public static void Main() { Task.Run(async () => await MainAsync()).GetAwaiter().GetResult(); } public static async Task MainAsync() { await

Where to store Connection String

我怕爱的太早我们不能终老 提交于 2021-02-07 14:39:27
问题 I am creating a Class Library which contains all the custom classes I regularly use in the applications I develop. This library is compiled and added as a Reference in each of my applications, enabling me to call on the custom classes contained within the library. The custom classes in my library include multiple layers of inheritance, but all ultimately have their origins in a base class I call 'Alpha'. In that class I also hold my connection string so that it is inherited by all other

Pass parameters correctly to SqlCommand

£可爱£侵袭症+ 提交于 2021-02-04 08:11:25
问题 I have code to insert data to SQL table. The columns have such types: @param1 datetime, @param2 nvarchar(50), @param3 int, @param4 bit, @param5 int, @param6 bit, @param7 bit, @param8 varchar(20), @param9 varchar(20) This is my method: try { using (SqlCommand oleDbCommand = new SqlCommand()) { // Set the command object properties oleDbCommand.Connection = new SqlConnection(connectionString); oleDbCommand.CommandType = CommandType.StoredProcedure; oleDbCommand.CommandText = "[dbo].[InsertRow]";

Pass parameters correctly to SqlCommand

大城市里の小女人 提交于 2021-02-04 08:09:30
问题 I have code to insert data to SQL table. The columns have such types: @param1 datetime, @param2 nvarchar(50), @param3 int, @param4 bit, @param5 int, @param6 bit, @param7 bit, @param8 varchar(20), @param9 varchar(20) This is my method: try { using (SqlCommand oleDbCommand = new SqlCommand()) { // Set the command object properties oleDbCommand.Connection = new SqlConnection(connectionString); oleDbCommand.CommandType = CommandType.StoredProcedure; oleDbCommand.CommandText = "[dbo].[InsertRow]";

Which ADO.NET DataSet/DataTable Methods Are Safe For Multiple Reader Threads?

丶灬走出姿态 提交于 2021-02-02 09:35:22
问题 I am creating a custom cache object for data that is relatively static and is periodically updated from the DB. I have chosen to use a strongly-typed DataSet to store the cached data. Now, access for reading and refreshing (clients cannot write to the cache, only refresh it) to the custom cache object is synchronized via ReaderWriterLockSlim. HOWEVER, I want to ensure that clients of the cache cannot corrupt the data (DataTables, DataRows, etc.) within the strongly-typed data set by

C# SQL Data Adapter System.Data.StrongTypingException

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-02 09:15:44
问题 I get my data from SQL to Dataset with Fill. It's just one table with two columns (CategoryId (int) and CategoryName (varchar)). When I look at my dataset after fill method, CategoryId Columns seems to be correct. But in the CategoryName I have a System.Data.StrongTypingExceptio n. What could that mean? Any Ideas? 回答1: When you get the value of a row/column in a typed dataset, by default it raises this exception when the value is DBNull. So string x = Row.CategoryName;//Raises this exception

C# SQL Data Adapter System.Data.StrongTypingException

安稳与你 提交于 2021-02-02 09:13:48
问题 I get my data from SQL to Dataset with Fill. It's just one table with two columns (CategoryId (int) and CategoryName (varchar)). When I look at my dataset after fill method, CategoryId Columns seems to be correct. But in the CategoryName I have a System.Data.StrongTypingExceptio n. What could that mean? Any Ideas? 回答1: When you get the value of a row/column in a typed dataset, by default it raises this exception when the value is DBNull. So string x = Row.CategoryName;//Raises this exception

Insert List(Of Integer) into SQL Server Table [duplicate]

允我心安 提交于 2021-01-29 08:00:26
问题 This question already has answers here : Bulk Insert of Generic List C# into SQL Server (3 answers) Closed 7 years ago . Is there a fast, efficient way in VB.NET/ADO.NET to insert large amount of data from Geneneric.List(Of Integer) into SQL Server table besides looping thru the list and issuing individual INSERT commands? I am limited to .NET 3.5 and SQL Server 2005. Thanks! 回答1: Ship XML with all the changes to a stored procedure. Here is an old example here: http://granadacoder.wordpress

Is it possible to execute a BACKUP statement using a parameterised query?

亡梦爱人 提交于 2021-01-29 03:23:52
问题 Iam using above sql command. But the parameters are not adding. I have 2 textboxes to specify location and name. but its not passing to the query. Any solution? SqlConnection con = new SqlConnection(CS); con.Open(); SqlCommand cmd= new SqlCommand("BACKUP DATABASE BillingSoftware TO DISK = '@Loc:\\@Name.BAK'",con); cmd.Parameters.AddWithValue("@Loc", textBox_BackupDatabaseLocation.Text); cmd.Parameters.AddWithValue("@Name", textBox_BackupDatabaseName.Text); cmd.ExecuteNonQuery(); 回答1: Instead

Executing Multiple Non-SELECT MySQL Statements as a Single Command Text in .NET

こ雲淡風輕ζ 提交于 2021-01-28 07:24:57
问题 I've been jumping from one thread to another but I can't seem to find the answer that I need. I wanted to execute non-SELECT MySQL statements in a single ExecuteNonQuery function using .NET. Here is a sample group of SQL statements I wanted to run: DROP procedure IF EXISTS `SubProcA`; DROP procedure IF EXISTS `SubProcB`; DROP procedure IF EXISTS `SubProcC`; CREATE PROCEDURE 'SubProcD'() BEGIN SELECT (<Subselect Statement>) AS A ,(<Subselect Statement>) AS B ,(<Subselect Statement>) AS C; END;