/
Program.cs
38 lines (26 loc) · 1.03 KB
/
Program.cs
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
using System;
namespace PHolaMySql
{
class MainClass
{
public static void Main (string[] args)
{
MySqlConnection mySqlConnection= new MySqlConnection("" +
"Server= localhost;Database=dbprueba;User ID = root; Password= sistemas"");
mySqlConnection.Open();
Console.WriteLine ("Hello World!");
MySqlCommand mySqlCommand= mySqlConnection.CreateCommand();
mySqlCommand.CommandText= string.Format("insert into categoria(nombre)values ('{0}')", DateTime.Now);
mySqlCommand.ExecuteNonQuery;
mySqlCommand.CommandText= "select * from categoria";
MySqlDataReader mySqlDataReader= mySqlCommand.ExecuteReader();
Console.WriteLine("FieldCount={0}", mySqlDataReader.FieldCount);
for(int index=0; index < mySqlDataReader.FieldCount; index++)
Console.WriteLine("colum{0}={1}", indexer, mySqlDataReader.getName(indexer));
while(mySqlDataReader.Read()){
object id= mySqlDataReader["nombre"];
Console.WriteLine("id={0} nombre={1}", id , nombre);
mySqlDataReader.Close();
mySqlConnection.Close();
}
}