3

ExecuteNonQuery Result in C #

 2 years ago
source link: https://www.codesd.com/item/executenonquery-result-in-c.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

ExecuteNonQuery Result in C #

advertisements

How can i know if i create a database successfully? I am using "CREATE DATABASE DemoDB" as a SQL command. ExecuteNonQuery() method returns 0. What should i use to understand if i created a database successfully?


ExecuteNonQuery throws a MySqlException exception if there is an error. It returns 0 if successful but you don't need to check the return value; if it returns normally it has succeeded. For example here is the exception I get when I try to create a database that already exists:

Can't create database 'name'; database exists

Related Articles

Pass the parameter to the stored procedure in C #

I have a stored procedure that returns a variable @result set to 1 or 0 (datatype bit). I am accessing it in my C# with the following code. Its throwing an error saying too many parameters. protected void btnRegister_Click(object sender, EventArgs e)

SQL Server 2008 R2 Express Edition - Exception

I am working on a a solution in C# where I can DROP a Database in SQL Server 2008 R2 Express Edition. I searched the WWW and found the following solution: Script to kill all connections to a database (More than RESTRICTED_USER ROLLBACK) I also tried

Validate connection errors

I am using the following C# code for a Login Page but I get an error that says: "Please make sure that the username and the password is Correct" protected void btnlogin_Click(object sender, EventArgs e) { int Results = 0; if (txtUsername.Text !=

The invalid connection giving a specified casting is invalid

I have a login form and modified some code from another source to make it work for my situation. I am getting the error when the login is not valid because the number is empty or 'infinite'. public int Validate_Login(String Username, String Password)

Error while running the MySQL query

Im trying to run this method but sometimes, it errors, sometimes it runs smoothly. I can't figure out what's going wrong. Any ideas? public bool NewArchive(string appId, string fileUrl, long length, string thumbUrl) { ConnectIfClosed(); string query

With regard to not calling enquiry.cs in the application code

I am a newcomer in .net , my problem is related to email. This code is well performed on my localhost. This is code of my enquiry.aspx.cs:- protected void Button1_Click(object sender, EventArgs e) { Mail mm = new Mail(); if (DropDownList3.SelectedIte

(VB.NET) Syntax error in INSERT INTO statement - MICROSOFT JET DATABASE ENGINE

I need help, I developed a simple Access database and I create a VB .Net user interface. I can't INSERT data into the Table here's my sample code... I'm only a beginner in VB.Net i hope you could help me with this one Dim con As New OleDbConnection D

Converting the DbCommand Object to the OracleCommand Object

I have inherited a function in an ASP.NET (C#) application where the author used the Microsoft.Practices.EnterpriseLibrary.Data library, but I have been asked to change it so that it uses System.Data.OracleClient. This function uses a stored procedur

The easiest way to create the database from the connection string?

We're looking for a hands-on way to create a database from a given connection string with minimum code possible (e.g., to include in LINQPad scripts or C# scriptlets). Is there a one-liner or something similar to create a database from a connection s

How can you update based on the results of an IF statement in the query?

As the question above says, I have an IF clause in my query. Now I want to do an UPDATE based on the results of the IF clause. Any ideas how I can do this? Here is my code: string cmdstr = "UPDATE itemsordered i " + "INNER JOIN" + &quo

If a query contains two update statements, what does ExecuteNonQuery () return?

if a query has two update statements what executenonquery will return? Will it club the row count affected in both the update statements OR will return the count updated in last statement?It return summary of total row affected of all statement. For

How do I export the results of a stored procedure directly to an MS Excel file?

I found a way to extract the contents of a MS Sql table directly (faster) to excel. But I do not know how to do this with a stored procedure that requires parameters. Is it possible to extract, directly, to an Excel File the results of a stored proce

Why does this method that runs this simple query give me a bad result?

I have the following problem. I have this Microsoft SQL Server query: Select AVG(Severity) AS 'Average Severity' from VulnerabilityAlertDocument that, executed into Microsoft SQL Server Managment Studio, return to me this float: 7,34792844929602 Now

SQL query always Return -1 as a result c # asp.net

In my code, am always getting the Value of 'user_id' as -1. is that anything Wrong in the Query??? and i am also want the join query for that. using (SqlConnection con = new SqlConnection(connectionString)) { try { SqlCommand cmd; if (con.State == Co

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK