sqlcommand

sqlcommand execute query not updating deleting and inserting

泪湿孤枕 提交于 2019-12-08 14:50:47
问题 Hello i always use SQlcommand for non query but now something wrong i dont know what i have 3 buttons with operations update insert and delete but i created unique method for all 3 operations, the problem is it doesn't insert delete or update: private void operacao(String operacao) { String comando = ""; con = new SqlConnection(); WorksDataSet dataset = new WorksDataSet(); con.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Works.mdf;Integrated Security=True

C# Update Table using SqlCommand.Parameters

浪尽此生 提交于 2019-12-07 07:05:19
问题 I'm trying to update an MSSQL table using SqlCommand, I think it's a syntax error with my T-SQL, but here is what I have so far: SqlCommand sqlCmd = new SqlCommand("UPDATE yak_tickets SET email = @emailParam, subject = @subjectParam, text = @textParam, statusid = @statusIDParam, ticketClass = @ticketClassParam WHERE id = @ticketIDParam", sqlConn); The parameters are working as they should, however, the table never gets updated when I run the code. Any help would be appreciated =) Here is the

SQLCommand ExecuteNonQuery Maximum CommandText Length?

跟風遠走 提交于 2019-12-07 02:48:47
问题 I've searched around the internet and everything seems to be about individual fields or doing one insert. I have a migration tool that is migrating from an old legacy database (superbase) to our SQL server DB (2008). Currently I'm reading 20,000 records from the old database and generating one big SQLCommand.CommandText string with 20,000 insert statements delimited by a semicolon. This works fine . But can I do 25k? 30k? I tried not having any limit at all, but when I tried to run

Parsing a SQL string in c#

喜你入骨 提交于 2019-12-06 05:59:17
问题 I have the need to Parse a Command.CommandText . I don't want to run the query. I only want to see if the query will succeed if the command was executed. Say i have; "SELECT * FROM SomeTable WHERE (1=1)" This string will succeed. but, "SELECT * FROM SomeTable WHERE (1=1" will not succeed. Now my question. How would i Parse this string c# ? 回答1: If you just want to validate the syntax. You can use Microsoft.Data.Schema.ScriptDom for this. using Microsoft.Data.Schema.ScriptDom; using Microsoft

C# Update Table using SqlCommand.Parameters

≡放荡痞女 提交于 2019-12-05 11:20:32
I'm trying to update an MSSQL table using SqlCommand, I think it's a syntax error with my T-SQL, but here is what I have so far: SqlCommand sqlCmd = new SqlCommand("UPDATE yak_tickets SET email = @emailParam, subject = @subjectParam, text = @textParam, statusid = @statusIDParam, ticketClass = @ticketClassParam WHERE id = @ticketIDParam", sqlConn); The parameters are working as they should, however, the table never gets updated when I run the code. Any help would be appreciated =) Here is the rest of the code: #region Parameters /* Parameters */ sqlCmd.Parameters.Add("@ticketIDParam", SqlDbType

Executing an SQLCommand without specifying a Transaction

点点圈 提交于 2019-12-05 09:53:38
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 ? SQL Server can work happily without an explicit transaction. But yes, I believe it is essentially read-committed (unless, of course, you add extra hints to your query objects,such as UPDLOCK

Is this Sql-injection-proof Asp.net code?

谁说我不能喝 提交于 2019-12-04 12:13:34
Problem: I have a form with text values, and a function that must return a string query based on the values of the text values too. Solution: I created a SQLCommand query with parameters, then I put the SQLCommand.CommandText to a string and I returned it (to the business logic that is going to handle the query) Main Question: Is it sql-injection proof? Code Example: sQuery = "select * from xy where x like '%@txtNameParameter%'"; SqlCommand cmd = new SqlCommand(sQuery); cmd.Parameters.Add("@txtNameParameter", SqlDbType.VarChar); cmd.Parameters["@txtNameParameter"].Value = txtName.Text; string

SqlCommand.Cancel() causes a performance boost?

为君一笑 提交于 2019-12-04 11:05:34
问题 I have seen this show up several places in code, never with an explanation, just a cryptic comment above it (Declaration and execution included for an idea of context. It's just a standard procedure of running a SqlCommand): //SqlCommand cmd = new SqlCommand(); //cmd.ExecuteReader(); //Read off the results //Cancel the command. This improves query time. cmd.Cancel (); Basically, after finishing a query, it goes back and cancels it, claiming some performance boost. I suppose you might get some

SqlCommand (Using Statement / Disposing issue)

帅比萌擦擦* 提交于 2019-12-04 02:34:51
Take the following example... Using cn As New SqlConnection(ConnectionString) Try Dim cmd As SqlCommand = New SqlCommand With cmd .Connection = cn .Connection.Open() .CommandText = "dbo.GetCustomerByID" .CommandType = CommandType.StoredProcedure .Parameters.Add("@CustomerID", SqlDbType.Int, 4) .Parameters("@CustomerID").Value = CustomerID End With da = New SqlDataAdapter(cmd) da.Fill(ds, "Customer") Catch ex As Exception End Try End Using From my research today is sounds as though this is basically okay but the SqlCommand is not being disposed of. Question -> Which of the following examples is

C# SqlDataReader Execution Statistics and Information

▼魔方 西西 提交于 2019-12-03 13:36:11
问题 I am creating an automated DB Query Execution Queue, which essentially means I am creating a Queue of SQL Queries, that are executed one by one. Queries are executed using code similar to the following: using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString)) { cn.Open(); using (SqlCommand cmd = new SqlCommand("SP", cn)) { cmd.CommandType = CommandType.StoredProcedure; using (SqlDataReader dr = cmd.ExecuteReader()) {