El nombre "conectar" no existe en el contesto actual
Publicado por sergio (45 intervenciones) el 23/07/2016 02:02:12
el error me lo marca en el finally del try, y no puedo cerrar la conexion, alguna ayuda?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
public static DataTable conexionmysql()
{
try
{
string conex;
//server34.hostinger.com.ar
//mysql.hostinger.com.ar
//31.170.166.34
//conex = @"Server=server34.hostinger.com.ar; database=u996372503_agend; uid=u996372503_agend; pwd=sfcl0810;";
conex = @"Server=localhost; database=miagenda; uid=root";
MySqlConnection conectar = new MySqlConnection(conex);
conectar.Open();
MySqlCommand registros1 = new MySqlCommand("select * from miagenda", conectar);
MySqlDataAdapter adaptador = new MySqlDataAdapter(registros1);
DataSet dst = new DataSet();
adaptador.Fill(dst);
//int param = dst.Tables[0].Rows.Count;
//if (param > 0)
//{
return dst.Tables[0];
}
//}
//catch (Exception ex)
//{
// return MessageBox.Show(ex.Message);
//} // end catch
finally
{
conectar.Close();
} //
}
Valora esta pregunta


0