ado.net

How to Prepare an ADO.NET Statement which includes an NText (clob) parameter

强颜欢笑 提交于 2019-12-20 05:26:08
问题 I'm updating an existing application which uses a factory to build prepared statements, and then execute them later, which works for the rest of the system, but I've been tasked with adding a call to a statement which uses an NText, and I cannot figure out how to properly prepare the statement. I am getting a runtime error of "SqlCommand.Prepare method requires all variable length parameters to have an explicitly set non-zero Size." but I'm not sure what value to use for the Length Obligatory

Error: Time-out interval must be less than 2^32-2. Parameter name: dueTm

≡放荡痞女 提交于 2019-12-20 05:20:10
问题 I have a one-to-many relationship within my class model. Example: A single role can have many permissions attached to it. so have two table one from the role and one for the permissions for each role. Now i have a role class which in turn has a permission list as a member of that class. When i need to do an update, i instantiate a transactionscope object, and do an update for the role. After that is done and with the transactionscope still open, i open another transactionscope for each

SqlDataAdapter.Fill() within a SqlTransaction - is this a bad practice?

梦想与她 提交于 2019-12-20 04:19:07
问题 Since I have a "DB util" class with a DataSet QueryDB(string spName, DBInputParams inputParams) method which I use for all my calls to the database, I would like to reuse this method in order to support transacted calls. So, at the end I will have a SqlDataAdapter.Fill within a SqlTransaction. Will this be a bad practice? Because rarely I see usage of DataAdapter.Fill within a transaction and more often ExecuteReader(). Is there any catch? Edit1: The thing is that inside my transaction is

Correct way to have a DataGridView visually reflect changes in its DataSource

心已入冬 提交于 2019-12-20 04:13:44
问题 Say a DataGridView has its DataSource property set to a DataView instance. DataGridView dgv; DataTable dt; // ... dt gets populated. DataView dv = dt.DefaultView; dgv.DataSource = dv; // ... dt gets modified // The DataGridView needs to update to show these changes visually // What goes here? I know you could set dgv.DataSource to null , then back to dv . But that seems pretty weird. I'm sure there are a couple of other ways, too. But what's the correct, official way to do this? 回答1: The

Parallel ForEach with SQL inserts c#

試著忘記壹切 提交于 2019-12-20 03:52:12
问题 I have an object like the below but with a huge amount of data, we observed that it takes a long to be inserted into our SQL database as we were using normal foreach , the main idea is to insert each Department and get the generated identity number, then insert the nested employees assigned with that department ID. <Sample> <Departments> <Department> <Name>HR</Name> <Employees> <Employee> <Name>Marco</Name> </Employee> <Employee> <Name>John</Name> </Employee> <Employee> <Name>Sarah</Name> <

How to return table name from stored procedure in dataset

自闭症网瘾萝莉.ら 提交于 2019-12-20 03:43:06
问题 I used a dataset to store 15 tables that I need at the time of loading. When i filled all the tables using stored procedure it returns me all the table but name of the table doesn't comes as that of actual table name in a database. It takes all the table with table name as Table1, Table2, Table3... I want them to be with the name as they actually are in table. SELECT PK_GUEST_TYPE, [DESCRIPTION] FROM L_GUEST_TYPE SELECT PK_AGE_GROUP_ID, AGE_GROUP FROM L_AGE_GROUP SELECT PK_COMPANY_ID, COMPANY

Bind datagrid to datareader

陌路散爱 提交于 2019-12-20 03:16:54
问题 I want to be able to enter SQL into a textbox and display the results in a WPF Datagrid. I thought to start with an SqlDataReader , and set the datagrid's ItemsSource to the data reader: using (var cmd = conn.CreateCommand()) { cmd.CommandText = sql.Text; sqlResults.ItemsSource = cmd.ExecuteReader(); } but this fails with the following error: Invalid attempt to call FieldCount when reader is closed , which I understand to mean that by the time WPF gets around to reading the FieldCount

“Data source name not found and no default driver specified” for creating access connection

丶灬走出姿态 提交于 2019-12-20 02:47:20
问题 This is my connection to an access database in .NET: OdbcConnection conn = new OdbcConnection("Driver={Microsoft Access Driver (*.mdb)};Dbq=" + path + "\\Access.mdb;Uid=;Pwd=;"); And I got this problem: base {System.Data.Common.DbException} = {"ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified"} I have tried couple of database connection strings from here: http://www.connectionstrings.com/access but none of them working. Any suggestions

Entity Framework 4.1 : The navigation property 'BusinessUser' declared on type 'Login' has been configured with conflicting multiplicities

我的未来我决定 提交于 2019-12-20 02:43:24
问题 I am having two entities BusinessUser { Id(PK), Name,...} Login { BusinessUserID(PK, FK), Email, Password, etc...} Relationship between BusinessUser and Login is one-to-zero/one . I am having following configurations In BusinessUser EF configuration class this.HasOptional(bu => bu.LoginInfo) .WithOptionalPrincipal(l => l.BusinessUser); In Login EF configuration class this.HasRequired(l => l.BusinessUser) .WithOptional(bu => bu.LoginInfo); I am getting following exception The navigation

Execute Scalar to trap error in case of no records returned

笑着哭i 提交于 2019-12-20 02:32:08
问题 I have got this code below: Dim lJobName As String = "" SQLCommand.CommandText = "Select JobName from Jobs where Id = @Id " SQLCommand.Parameters.Add(New SqlParameter("@Id", SqlDbType.Int)) SQLCommand.Parameters(0).Value = var_id lJobName = SQLCommand.ExecuteScalar() Issue how to catch if no records are found? 回答1: I try to avoid comparing a string to Nothing, even though it does work in VB. The Visual Basic .NET runtime evaluates Nothing as an empty string; that is, "". The .NET Framework,