ado.net

Total rows that we can add to datatable

☆樱花仙子☆ 提交于 2019-12-30 22:16:46
问题 I wants to know whether there is any limit for number of rows that we can add to datatable. I am doing this in C# and .NET 2005. Actually my application is reading large text file around 40 MB,application reads text file line by line and adds it as row in datatable once all file reads then calls update method to update data to database. I am not sure how many rows we can add to datatable. I just want to make my application secure from throwing any error in future if file size again increase.

Getting concurrency error on updating record with data adapter

血红的双手。 提交于 2019-12-30 14:44:53
问题 This is my table: Student : StudentId int PK autoincrement,Name varchar(20) When i am trying to update last added records then i am geting error: Error : Concurrency violation: the UpdateCommand affected 0 of the expected 1 records. This is my code: using (var connection = new SqlConnection("MyConnectionstring")) { connection.Open(); SqlDataAdapter adapter = new SqlDataAdapter(); SqlCommandBuilder builder = new SqlCommandBuilder(adapter); adapter.SelectCommand = new SqlCommand("select * from

How to create a C# class whose attributes are rows in a database table with ADO.NET?

家住魔仙堡 提交于 2019-12-30 11:20:17
问题 Is it possible? Please note I am not using LINQ nor Entity Framework. 回答1: You could also check out Dapper-Dot-Net - a very lightweight and very capable "micro ORM" which - incidentally - is used to run this site here. It's quite fast, a single *.cs file, works with your usual T-SQL commands and returns objects - works like a charm, it's very fast, very easy to understand, no big overhead - just use it and enjoy! 回答2: My personal favorite is done using the dynamic object featured in .NET4 via

What's the alternative to DataTable with ADO.NET under MVC 6?

折月煮酒 提交于 2019-12-30 06:42:08
问题 I am creating a MVC 6 project and I would rather use Classic ADO.net over Entity Framework 7. However It is saying that name space can not be found for both DataTable and SqlDataAdapter . I have a using System.Data and System.Data.SqlClient statement. It dose not show an error until I try to build the project. I think I read somewhere that those two names spaces are not implemented in the new version. If so is there an alternative way of doing it or am I missing a dependency or using

SQL Injection Prevention in .NET

时光毁灭记忆、已成空白 提交于 2019-12-30 04:49:13
问题 I typically write my SQL as so in .NET sql.Append("SELECT id, code, email FROM mytable WHERE variable = @variable "); Then do something like this: using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings[ConfigurationManager.AppSettings["defaultConnection"]].ConnectionString)) { using (SqlCommand myCommand = new SqlCommand(sql.ToString(), conn)) { myCommand.Parameters.AddWithValue("@variable", myVariableName"); ... But should I also do this addParameter when the

How do I get the SqlDbType of a column in a table using ADO.NET?

Deadly 提交于 2019-12-30 03:23:26
问题 I'm trying to determine at runtime what the SqlDbType of a sql server table column is. is there a class that can do that in System.Data.SqlClient or should I do the mapping myself? I can get a string representation back from SELECT DATA_TYPE, CHARACTER_MAXIMUM_LENGTH FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_CATALOG = '{0}' AND TABLE_SCHEMA = '{1}' AND TABLE_NAME = '{2}' AND COLUMN_NAME = '{3}' EDIT: I can't use SMO as I have no control over the executing machine so I can't guarantee it

What is the best data access paradigm for scalability?

好久不见. 提交于 2019-12-29 11:41:25
问题 There are so many different options coming out of microsoft for data access. Which one is the best for scalable apps? Linq Should we be using Linq? It certainly seems easy but if you know your SQL does it really help. Also I hear that you can't run Async queries in ASP.NET using Linq. Therefore I wonder if it is really scalable? Are there any really big sites using Linq (With the possible exception of stackoverflow). Entity Framework Don't hear so much razzmatazz about the Entity Framework.

How to use MySQL user-variables with ADO.NET

痴心易碎 提交于 2019-12-29 09:05:53
问题 MySQL SQL commands can contain user variables that start with '@'. The MySQL ADO.NET connector also uses '@' for command parameters. Is there a way to escape the '@' character so I can use a user-variable in an SQL statement sent to MySQL via ADO.NET? I'm trying to do something like this: UPDATE company SET next_job_id = @jobid:=next_job_id+1 WHERE company_id = @companyid; SELECT @jobid; Where @jobid is a MySQL user variable and @companyid is a parameter. 回答1: It's a connection string option

How to populate DataTable with anonymous LINQ result

限于喜欢 提交于 2019-12-29 08:43:18
问题 I have the following LINQ query: var timesheets = from timesheet in entities.Timesheets join timesheetTask in entities.Timesheet_Task on timesheet.Id equals timesheetTask.Timesheet_Id join task in entities.Tasks on timesheetTask.Task_Id equals task.Id join project in entities.Projects on task.Project_Id equals project.Id join department in entities.Departments on project.Department_Id equals department.Id where timesheet.Employee_Id == employeeId select new { date = timesheet.Date, taskName =

How can I Pass a Table Name to SqlCommand?

不想你离开。 提交于 2019-12-29 07:59:48
问题 I am trying to pass a table name as a parameter to my query through SqlCommand but it doesn't seems to be working. Here is my code; SqlConnection con = new SqlConnection( "server=.;user=sa;password=12345;database=employee" ); con.Open( ); SqlCommand cmd = new SqlCommand( "drop table @tbName" , con ); cmd.Parameters.AddWithValue( "@tbName" , "SampleTable" ); cmd.ExecuteNonQuery( ); con.Close( ); 回答1: SqlCommand.Parameters are supported for Data manipulation language operations not Data