ado.net

Why is my SqlCommand returning a string when it should be an int?

风流意气都作罢 提交于 2019-12-20 14:44:35
问题 I have a query that should always be returning a single int. I have now logged it returning a string entirely unrelated to what it should be. We've been getting some random FormatExceptions that we've tracked down to several database queries. After some additional logging, I found that, this morning, the query below returned the string "gladiator". Website.PkID is an int column and works most of the time, but some times it fails miserably and returns either an int that's waaaay out there

How to track changes in many SQL Server databases from .NET application?

試著忘記壹切 提交于 2019-12-20 14:09:23
问题 Problem: There are a lot of different databases, which is populated by many different applications directly (without any common application layer). Data can be accessed only through SP (by policy) Task: Application needs to track changes in these databases and react in minimal time. Possible solutions: 1) Create trigger for each table in each database, which will populate one table with events. Application will watch this table through SqlDependency. 2) Watch each table in each database

Sybase ASE ADO.net 2.0 provider?

被刻印的时光 ゝ 提交于 2019-12-20 12:39:01
问题 I'm looking for an ADO.net 2.0 or later provider for Sybase database which seems to be known as Sybase ASE. To clarify, I'm interested in ASE, and not SQL Anywhere. Hopefully the provider will be included with the database, or free. I can find mention of an ADO.net 1.1 provider; that's not what I want. I can find mention of ODBC drivers and OLEDB providers; that's not what I want. I've found the DataDirect ADO.net providers which are paid for; I guess that's the fallback position. Thanks for

How to pass parameter to sql 'in' statement?

一笑奈何 提交于 2019-12-20 12:35:13
问题 I want to create this query: select * from products where number in ('123', '234', '456'); but I can't find any example of achiving this with Npgsql and NpgsqlParameter. I tried like this: string[] numbers = new string[] { "123", "234" }; NpgsqlCommands cmd = new NpgsqlCommands("select * from products where number in (:numbers)"); NpgsqlParameter p = new NpgsqlParameter("numbers", numbers); command.Parameters.Add(p); but it didn't work ;) 回答1: Pass it as an array: string[] numbers = new

Is there a dynamic Sql builder library for .Net? [closed]

感情迁移 提交于 2019-12-20 10:29:59
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . Something like this. http://code.google.com/p/squiggle-sql/wiki/Tutorial. This is required for cases where It is required to build complex sql from the user input from UI. Currently in the project I am working is using String Manipulation which looks ugly and is difficult to maintain. 回答1: Try DbExtensions,

Using TransactionScope around a stored procedure with transaction in SQL Server 2014

余生长醉 提交于 2019-12-20 09:04:39
问题 I am using C# and ADO.Net with a TransactionScope to run a transaction in an ASP.Net app. This transaction is supposed to save some data across multiple tables and then send an email to subscribers. Question : is it a valid use of TransactionScope , when it includes a call to a stored procedure that has its own transaction in SQL Server 2014, or should I remove the SQL transaction statements i.e. begin tran , commit tran and rollback tran statements from the stored procedure being called

how to update row in DataGridView?

孤人 提交于 2019-12-20 07:40:45
问题 I have a DataGridView that is populated from a DataSet. How can I change any cell in the DataGridView , and have this change the DataSet too (and the Database). Is there a sample program for this (in C#) that I can learn from? 回答1: Here is an article with clear explanations, screenshots, and code that demonstrates how to use the DataGridView. The data binding sections should be of particular interest. 回答2: DataRowView drv = dataGridView1.CurrentRow.DataBoundItem as DataRowView; DataRow[]

Getting Data from Access into a text box in C# by clicking a button

前提是你 提交于 2019-12-20 07:39:34
问题 I have a table in MS Access that contain: (FoodID, FoodName, Price). In C# I have three text boxes (txtId, txtName, txtPrice) and a button (btnSearch). My question is that, In C# I just type FoodID in (txtId) and then click on button Search It'll display FoodName and Price ( from table access) in txtName and txtPrice by itself. I got the source code from you but it error on (OleDbDataReader dr = cmd.ExecuteReader();) its message is "Data type mismatch in criteria expression" . Please solve

Read only queries Using ADO.NET

混江龙づ霸主 提交于 2019-12-20 06:43:09
问题 I want to limit the application to read only queries. In other words, I want the application to process only those queries which are not changing the state of the database. I am using ADO.NET. I do not want to create a new user against the database with read only permissions. Any suggestions are welcome. 回答1: Option 1: SQL Authentication You can use connections as shown below: Server ={serverName}; Initial Catalog = {DB_Name}; User Id={uid}; Password={pwd}; Use the uid which has only read

Invalid character in a Base-64 string for connection string

若如初见. 提交于 2019-12-20 05:44:15
问题 I have a Sql Server 2008 R2 connection string that looks like <add name="DBConnectionString" providerName="System.Data.SqlClient" connectionString="Data Source=AYZ;Initial Catalog=AYZ;User ID=AYZ;Password=AYZ;"/> When trying to create a new instance of SQLDatabase using EnterpriseLibrary.Data I get the above error. connString =ConnectionStrings.ConnectionStrings["DBConnectionString"]; Database objDB = new SqlDatabase(connString); connString has the following Data Source=AYZ;Initial Catalog