sqlcommand

Which pattern is better for SqlConnection object?

耗尽温柔 提交于 2019-12-23 16:28:13
问题 Which pattern is better for SqlConnection object? Which is better in performance? Do you offer any other pattern? class DataAccess1 : IDisposable { private SqlConnection connection; public DataAccess1(string connectionString) { connection = new SqlConnection(connectionString); } public void Execute(string query) { using (SqlCommand command = connection.CreateCommand()) { command.CommandText = query; command.CommandType = CommandType.Text; // ... command.Connection.Open(); command

Which pattern is better for SqlConnection object?

本秂侑毒 提交于 2019-12-23 16:28:09
问题 Which pattern is better for SqlConnection object? Which is better in performance? Do you offer any other pattern? class DataAccess1 : IDisposable { private SqlConnection connection; public DataAccess1(string connectionString) { connection = new SqlConnection(connectionString); } public void Execute(string query) { using (SqlCommand command = connection.CreateCommand()) { command.CommandText = query; command.CommandType = CommandType.Text; // ... command.Connection.Open(); command

Executing an SQLCommand without specifying a Transaction

时间秒杀一切 提交于 2019-12-22 05:54:24
问题 We have some lists of data being fetched in our application via a SqlCommand performing a SELECT query on a SQL Server database. We do not explicitly setup a transaction on the SqlCommand, instead just passing it a SqlConnection and running it. Is it the case that when no transaction is specified that SQL Server will initiate and use a default transaction with the default IsolationLevel of ReadCommitted ? 回答1: SQL Server can work happily without an explicit transaction. But yes, I believe it

I'm getting an error in SQL command not properly ended

自作多情 提交于 2019-12-19 17:44:50
问题 when I enter this INSERT INTO works_on (essn, pno, hours) values ('123456789', 1, 32.5), ('123456789', 2, 7.5), ('666884444', 3, 40.0), ('453453453', 1, 20.0), ('453453453', 2, 20.0), ('333445555', 2, 10.0), ('333445555', 3, 10.0), ('333445555', 10, 10.0), ('333445555', 20, 10.0), ('999887777', 30, 30.0), ('999887777', 10, 10.0), ('987987987', 10, 35.0), ('987987987', 30, 5.0), ('987654321', 30, 20.0), ('987654321', 20, 15.0), ('888665555', 20, 0); I get the follow error ORA-00933: SQL

Should I migrate to Entity Framework? [closed]

不想你离开。 提交于 2019-12-19 03:11:42
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . I've been using the SqlCommand class and writing my own T-SQL queries for a very long time. I've stuck with it because I'm comfortable with it, and it probably stemmed from me starting as a windows developer in the days before we had many other great options. I've been doing

C# multiple parallel inserts in database

懵懂的女人 提交于 2019-12-18 17:05:29
问题 I have a datatable with around 3000 rows. Each of those rows need to be inserted in a database table. Currently, i am running a foreach loop as under: obj_AseCommand.CommandText = sql_proc; obj_AseCommand.CommandType = CommandType.StoredProcedure; obj_AseCommand.Connection = db_Conn; obj_AseCommand.Connection.Open(); foreach (DataRow dr in dt.Rows) { obj_AseCommand.Parameters.AddWithValue("@a", dr["a"]); obj_AseCommand.Parameters.AddWithValue("@b", dr["b"]); obj_AseCommand.Parameters

Create SQL Server table programmatically

空扰寡人 提交于 2019-12-18 08:53:11
问题 I need to programmatically create a SQL Server 2008 table in C# such that the columns of the table should be generated from a list of columns (each column name is the name of a row in the table) My question is what is the command string to loop through the list of columns and creates the table's recorded: List<string> columnsName = ["col1","col2","col3"] I want to create a table with the columns in the columnsName . But since the list size in not constant, I need to loop through the list to

What SQL is being sent from a SqlCommand object

北战南征 提交于 2019-12-18 07:09:26
问题 I have a SqlCommand object on my c# based asp.net page. The SQL and the passed parameters are working the majority of the time. I have one case that is not working, I get the following error: String or binary data would be truncated. The statement has been terminated. I understand the error and but all the columns in the database should be long enough to hold everything being sent. My questions, Is there a way to see what the actual SQL being sent to the database is from SqlCommand object? I

ExecuteNonQuery inside loop

我是研究僧i 提交于 2019-12-18 04:50:47
问题 I'm trying to insert a database record inside a loop in C#. It works when I hard code the values like this: string query3 = "INSERT INTO furniture (room_id,member_id) VALUES (222,333);"; SqlCommand cmd3 = new SqlCommand(query3, sqlConnection3); sqlConnection3.Open(); for (int i = 0; i < arrItemsPlanner.Length; i++) { try { cmd3.ExecuteNonQuery(); } catch { return "Error: Item could not be saved"; } finally { //Fail } } But when I use parameterised queries it doesn't work - even if I hard code

How to pass variable into SqlCommand statement and insert into database table

微笑、不失礼 提交于 2019-12-17 21:11:38
问题 I'm writing a small program in C# that uses SQL to store values into a database at runtime based on input by the user. The only problem is I can't figure out the correct Sql syntax to pass variables into my database. private void button1_Click(object sender, EventArgs e) { int num = 2; using (SqlCeConnection c = new SqlCeConnection( Properties.Settings.Default.rentalDataConnectionString)) { c.Open(); string insertString = @"insert into Buildings(name, street, city, state, zip, numUnits)