2 // TestParameters.cs - test parameters for the MySQL .NET Data Provider in Mono
3 // using *Parameter and *ParameterCollection
5 // Note: it currently only tests input parameters. Output is next on the list.
6 // Then output/input and return parameters.
9 // Daniel Morgan <danmorg@sc.rr.com>
11 // (c)copyright 2002 Daniel Morgan
15 using System
.Collections
;
17 using Mono
.Data
.MySql
;
19 namespace TestMonoDataMySql
{
21 public class TestParameters
{
22 public static void Main() {
23 Console
.WriteLine("** Start Test...");
25 String connectionString
= null;
30 Console
.WriteLine("** Creating connection...");
31 con
= new MySqlConnection(connectionString
);
32 Console
.WriteLine("** opening connection...");
35 string charValue
= "CD";
38 sql
= "SELECT char_value, int_value FROM mono_mysql_test WHERE char_value = :inCharValue";
40 Console
.WriteLine("** Creating command...");
41 MySqlCommand cmd
= new MySqlCommand(sql
, con
);
43 // add parameter for inTableName
44 Console
.WriteLine("** Create parameter...");
45 MySqlParameter parm
= new MySqlParameter("inCharValue", DbType
.String
);
47 Console
.WriteLine("** set direction of parameter to input");
48 parm
.Direction
= ParameterDirection
.Input
;
50 Console
.WriteLine("** set the parameter value...");
51 parm
.Value
= charValue
;
53 Console
.WriteLine("** add parameter to parameters collection in the command...");
54 cmd
.Parameters
.Add(parm
);
57 Console
.WriteLine("** ExecuteReader()...");
59 rdr
= cmd
.ExecuteReader();
61 Console
.WriteLine("[][] And now we are going to our results [][]...");
66 Console
.WriteLine("Result Set " + results
+ "...");
68 // get the DataTable that holds
70 DataTable dt
= rdr
.GetSchemaTable();
72 // number of columns in the table
73 Console
.WriteLine(" Total Columns: " +
77 foreach (DataRow schemaRow
in dt
.Rows
) {
78 foreach (DataColumn schemaCol
in dt
.Columns
)
79 Console
.WriteLine(schemaCol
.ColumnName
+
81 schemaRow
[schemaCol
]);
85 string output
, metadataValue
, dataValue
;
88 // Read and display the rows
90 Console
.WriteLine(" Row " + nRows
+ ": ");
92 for(c
= 0; c
< rdr
.FieldCount
; c
++) {
94 DataRow dr
= dt
.Rows
[c
];
101 if(rdr
.IsDBNull(c
) == true)
102 dataValue
= " is NULL";
108 // display column meta data and data
109 output
= metadataValue
+ dataValue
;
110 Console
.WriteLine(output
);
114 Console
.WriteLine(" Total Rows: " +
116 } while(rdr
.NextResult());
117 Console
.WriteLine("Total Result sets: " + results
);