Jesoba.com is launched, Click below image to access it

Jesoba.com is launched, Click below image to access it
Technology and Entertainment Blog

How to make Fuction for ExecuteNonQuery in C#.Net And VB.Net

Title : How to make Function for ExecuteNonQuery in C#.Net And VB.Net.

Article ID : C001

Create Class 'Functions' And Use Following Code : -
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
public class Functions
{



    SqlConnection sqlcon;
    SqlCommand cmd = new SqlCommand();    

    public Functions()
       {
        sqlcon = new SqlConnection(@"Data Source=.\SQL2005; Initial Catalog=VSPLHR2011; Integrated  Security = True");
       }

     public void CreateMySqlCommand(string myExecuteQuery)
       {
        SqlCommand myCommand = new SqlCommand(myExecuteQuery, sqlcon);
        myCommand.Connection.Open();
        myCommand.ExecuteNonQuery();
        sqlcon.Close();
       }
}


Use Below Code in your Project  Code file : -

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Collections;
public partial class InitComp : System.Web.UI.Page
{
    string sSqlStr;
    Functions fun = new Functions();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
          
        }
    }
  protected void btnSave_Click(object sender, EventArgs e)
    {
    sSqlStr = "INSERT INTO CompanyH ( IdCompanyH,  CompanyName,  TagLine) Values ( @IdCompanyH,    @CompanyName,  @TagLine);
    fun.CreateMySqlCommand(sSqlStr);
    }

}

Google+ Badge

About Author

My photo

I am Senior Server Expert and Professional Blogger.