Click here to Skip to main content
15,891,597 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
public class clsCon:System.Web.UI.Page
    {
       
        public static SqlConnection conn_new = new SqlConnection();


        public static SqlConnection connect(string strConStr)
        {
            try
            {


                if (conn_new.State != System.Data.ConnectionState.Open)
                {
                    conn_new.ConnectionString = strConStr;
                    conn_new.Open();
                }
                else
                {
                    return null;
                }
               

            }

            catch
            {
               

            }
            return conn_new;
        }

        public static SqlDataReader ReadTable(string strReadStr)
        { 
              
                SqlCommand COMMA = new SqlCommand(strReadStr, conn_new);
                SqlDataReader rdNew;
                rdNew = COMMA.ExecuteReader();
                return rdNew;
                
                        
        }

        public static Boolean AddEditDel(string strAddEditDel)
        {
            SqlCommand ADDCOM = new SqlCommand(strAddEditDel, conn_new);
            int a;
            a = ADDCOM.ExecuteNonQuery();
            if (a == 0)
                return false;
            else
                return true;


        }
      

      
Posted
Updated 14-Oct-12 18:57pm
v2
Comments
chathu027 15-Oct-12 0:28am    
is there a any Error ???
Prasad_Kulkarni 15-Oct-12 0:41am    
Not clear.
chathu027 15-Oct-12 0:52am    
if there any coding Error, It show some errors
chathu027 15-Oct-12 0:53am    
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Configuration;

///
/// Summary description for All
///

///
namespace Pos.Ep.DataAccess
{
public class Embus
{
SqlDataReader rdRStatus;
public Embus()
{
//
// TODO: Add constructor logic here
//
}

public Boolean Table_Add(string x,string y)
{
bool ExProduct = false;

try
{
String connStr = ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString;
con.ep.DAccess.clsCon.connect(connStr);
String inserttbl = "INSERT INTO Table2(cloumn1,coloumn2)VALUES('" + x+ "','" + y + "')";
ExProduct = Pos.Ep.DataAccess.clsCon.AddEditDel(inserttbl);


}
catch (Exception ex)
{

}
finally
{
clsCon.conn_new.Close();

} //finally

return ExProduct;
}




public boolean Getvalues(String x)
{
try
{//try

String connStr = ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString;
Pos.Ep.DataAccess.clsCon.connect(connStr);


String sqlstatus = "SELECT * from Table1 where id='" + x + "'";

rdRStatus = clsCon.ReadTable(sqlstatus);


if (rdRStatus.Read())
{
rdRStatus["coloumn_name"].ToString());
}


}//try


catch (Exception err)
{

}

finally
{

clsCon.conn_new.Close();
rdRStatus.Close();
} //finally
return Getbns;



}


#region update

public Boolean Update(String x, Decimal y)
{
Boolean upd2 = false;
try

String connStr = ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString;
Pos.Ep.DataAccess.clsCon.connect(connStr);
String updtxt2 = "UPDATE Table SET coloumn1='" + x +',Last_Modify='" + System.DateTime.Now + "' WHERE id='" + y + "'";
upd2 = clsCon.AddEditDel(updtxt2);

}

catch (Exception err)
{


}

finally
{
clsCon.conn_new.Close();

}

return upd2;
}

#endregion

}
}
chathu027 15-Oct-12 0:54am    
that is hw i call that connection ??

1 solution

First of all, this question has nothing to do with ASP.NET. It does not matter what type of application you are trying to use with the databases. Ever heard of separation of concerns?

It looks like you are lost pretty well. You just need to learn how ADO.NET works, from the overviews:
http://en.wikipedia.org/wiki/Ado.net[^],
http://msdn.microsoft.com/en-us/library/aa286484.aspx[^],
http://www.devlist.com/ConnectionStringsPage.aspx[^].

This CodeProject article will give you very short introduction with basic code samples:
Using ADO.NET for beginners[^].

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900