Ver Mensaje Individual
  #1 (permalink)  
Antiguo 29/06/2009, 13:11
Motki
 
Fecha de Ingreso: septiembre-2003
Mensajes: 341
Antigüedad: 20 años, 7 meses
Puntos: 0
CS0117: 'SqlServer_Connection' no contiene una definición para 'SQL_Update'

Hola a to2,
Estoy realizando una aplicacion con asp.net :
Dentro del directorio App_Code tengo un fichero llamado
conexion.cs que contiene lo siguiente :


Código conexion.cs:
Ver original
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Data.SqlClient;
  6. using System.Configuration;
  7. using System.Data;
  8. using System.Web.UI;
  9.  
  10. /// <summary>
  11. /// Descripción breve de conexion
  12. /// </summary>
  13. public class SqlServer_Connection
  14. {
  15. private static SqlConnection conn = null;
  16. public static SqlDataReader Reader = null;
  17.  
  18. public static ConnectionState Estado
  19. {
  20. get
  21. {
  22. if (conn == null)
  23. return ConnectionState.Broken;
  24. else
  25. return conn.State;
  26. }
  27. }
  28.  
  29.  
  30. public SqlServer_Connection()
  31. {
  32. //
  33. // TODO: Agregar aquí la lógica del constructor
  34. //
  35. SqlConnection conn;
  36. string ConnStr = ConfigurationManager.ConnectionStrings["xxxxxx"].ToString();
  37. conn = new SqlConnection(ConnStr);
  38.  
  39. try
  40. {
  41. conn.Open();
  42. }
  43. catch { throw new Exception("Error al conectar a la base de datos de Sql Server"); }
  44. }
  45.  
  46.  
  47. private static void Conectar()
  48. {
  49. string ConnStr = ConfigurationManager.ConnectionStrings["xxxxxx"].ToString();
  50. conn = new SqlConnection(ConnStr);
  51.  
  52. try
  53. {
  54. conn.Open();
  55. }
  56. catch { throw new Exception("Error al conectar a la base de datos de Sql Server"); }
  57. }
  58.  
  59.  
  60.  
  61.  
  62.  
  63. public static SqlDataReader SQL_Select(string sql)
  64. {
  65. if (Estado != ConnectionState.Open)
  66. {
  67. Conectar();
  68. if (Estado != ConnectionState.Open)
  69. return null;
  70. }
  71.  
  72. SqlCommand cmd = new SqlCommand(sql, conn);
  73. //SqlDataReader Reader = null;
  74. try
  75. {
  76. Reader.Dispose();
  77. Reader.Close();
  78. }
  79. catch { }
  80.  
  81. Reader = null;
  82. try
  83. {
  84. Reader = cmd.ExecuteReader();
  85. }
  86. catch { }
  87.  
  88. cmd.Dispose();
  89. return Reader;
  90. }
  91.  
  92.  
  93.  
  94. public static int SQL_Update(string sql)
  95. {
  96. try
  97. {
  98. if (Estado != ConnectionState.Open)
  99. {
  100. Conectar();
  101. if (Estado != ConnectionState.Open)
  102. return -1;
  103. }
  104.  
  105. try
  106. {
  107. Reader.Dispose();
  108. Reader.Close();
  109. }
  110. catch { }
  111.  
  112. Reader = null;
  113.  
  114. SqlCommand cmd = new SqlCommand(sql, conn);
  115.  
  116. int regafectados = cmd.ExecuteNonQuery();
  117. cmd.Dispose();
  118.  
  119. return regafectados;
  120. }
  121.  
  122. catch
  123. {
  124. return -1;
  125. }
  126. }
  127.  
  128.  
  129. }

luego en mi fichero
actualizar.cs tengo lo siguiente :


Código actualizar.cs:
Ver original
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Data;
  8. using System.Data.SqlClient;
  9.  
  10. public partial class datosDitca_centros_pruebaActualiza : System.Web.UI.Page
  11. {
  12. protected void Page_Load(object sender, EventArgs e)
  13. {
  14. string SQL1 = "update from xxx where id=1";
  15. int nada = SqlServer_Connection.SQL_Update(SQL1);
  16.  
  17. }
  18. }
Y obtengo el siguiente error :

CS0117: 'SqlServer_Connection' no contiene una definición para 'SQL_Update'

Alguien podria ayudarme a que se debe este error ??

Gracias
__________________
---Nuestra recompensa se encuentra en el esfuerzo y no en el resultado. Un esfuerzo total es una victoria completa.-- GHANDI