executenonquery

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)

ExecuteNonQuery inside of Reader

旧城冷巷雨未停 提交于 2019-12-13 21:08:24
问题 How can I solve this problem? I do not want to use two connections. ExecuteNonQuery only works if reader is closed. oleCnn = New System.Data.OleDb.OleDbConnection oleCnn.ConnectionString = ConnectionString oleCmm = New OleDb.OleDbCommand() oleCnn.Open() oleStr = "SELECT ID_Process FROM MyProcessTable" Dim reader As System.Data.OleDb.OleDbDataReader = oleCmm.ExecuteReader() While reader.Read() For i = 1 To NumExecutions oleStr = "INSERT INTO MyOtherProcessTable(reader.getInt32(0))" oleCmm

SqlParameter and ExecuteNonQuery causing unrepeatable time outs

╄→гoц情女王★ 提交于 2019-12-12 05:08:35
问题 I recently inherited some code that is having occasional time-out issues. I am mostly familiar with ORM's, so I am having trouble determining if anything is wrong in this code. When it does not time out, it works in a couple of seconds. Time-outs take about a minute. Here is the code: Dim sql As String = "UPDATE VendorInfo SET " & _ "AbsInkUpdateStatus=@AbsInkUpdateStatus, AccountingNotes=@AccountingNotes, " & _ "AccountNumber=@AccountNumber, Address_Ship=@Address_Ship, " & _ "Address0=

ADO.NET and ExecuteNonQuery: how to use DDL

﹥>﹥吖頭↗ 提交于 2019-12-12 01:18:31
问题 I execute SQL scripts to change the database schema. It looks something like this: using (var command = connection.CreateCommand()) { command.CommandText = script; command.ExecuteNonQuery(); } Additionally, the commands are executed within a transaction. The scrip looks like this: Alter Table [TableName] ADD [NewColumn] bigint NULL Update [TableName] SET [NewColumn] = (SELECT somevalue FROM anothertable) I get an error, because NewColumn does not exist. It seems to parse and validate it

Executenonquery return value

半城伤御伤魂 提交于 2019-12-11 08:56:59
问题 I want to perform a search on a table to see if record exists. I do not want to perform insert or update after. I have done this already but somehow I cannot get this to work. On my asp.net page I cannot seem to get any value returned. The error is "input string not in correct format" I ma sure it is obvious but I cannot seem to see it now! here is my code: Dim con As New SqlConnection("connstring") Dim cmd As New SqlCommand("checkname", con) cmd.CommandType = CommandType.StoredProcedure cmd

ExecuteNonQuery not working in C#

。_饼干妹妹 提交于 2019-12-11 03:30:32
问题 I am building a database using Visual Studio 2008 c# and when I'm a trying to insert a new record into my database it appears that ExecuteNonQuery has not initialized. I copy my code, hope anyone can help me in this because I am new. private void button1_Click(object sender, EventArgs e) { SqlConnection cn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Usuario\Documents\Visual Studio 2010\Projects\Nova\Nova\Database1.mdf;Integrated Security=True;User Instance=True");

my output parameters are always null when i use BeginExecuteNonQuery

﹥>﹥吖頭↗ 提交于 2019-12-11 00:27:13
问题 I have a stored procedure that returns a varchar(160) as an output parameter of a stored procedure. Everything works fine when i use ExecuteNonQuery, i always get back the expected value. However, once i switch to use BeginExecuteNonQuery, i get a null value for the output. I am using connString + "Asynchronous Processing=true;" in both cases. Sadly the BeginExecuteNonQuery is about 1.5 times faster in my case...but i really need the output parameter. Thanks! EDIT:This is how i am processing

How do I get the output from Database.ExecuteNonQuery?

我们两清 提交于 2019-12-10 15:58:13
问题 I would like to use the Database.ExecuteNonQuery or something similar to execute a sql script and then capture the output. eg: xxx Table created My script: strArray = Regex.Split(streamReader.ReadToEnd(), "\r\nGO"); if (connection.State == ConnectionState.Open) { System.Data.SqlClient.SqlCommand cmd; foreach (string sql in strArray) { cmd = new System.Data.SqlClient.SqlCommand(sql); cmd.Connection = connection; Console.WriteLine(sql); Console.WriteLine(cmd.ExecuteNonQuery().ToString()); } }

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

ExecutenonQuery not working

冷暖自知 提交于 2019-12-07 09:57:07
问题 I have stored proc as below: ALTER PROC pr_Update_Users_Nomination ( @UserID AS VARCHAR(100), @Nominated AS BIT ) AS UPDATE User SET isNominated = @Nominated WHERE EMPID = @UserID; I want to call this procedure from c# code: Below is the code I am trying: void OpenConnection() { string Nominated = "False"; //Connection String string sConnString = System.Configuration.ConfigurationManager.ConnectionStrings["ConString1"].ConnectionString; SqlConnection mySqlCon = new SqlConnection(sConnString);