主要是要变Windows下的GUI程序吧,哪位能给出清晰简单简洁的GUI代码示例?最好有通过ADO操作数据库的功能。C#的示例太差了!比如:// ADO\adosample.csusing System; using System.Data; using System.Data.ADO;public class MainClass { public static void Main () { // set Access connection and select strings string strAccessConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=BugTypes.MDB"; string strAccessSelect = "SELECT * FROM Categories"; //Create the dataset and add the Categories table to it DataSet myDataSet = new DataSet(); myDataSet.Tables.Add("Categories");
// create my Access objects ADOConnection myAccessConn = new ADOConnection(strAccessConn); ADODataSetCommand myAccessDataSetCmd = new ADODataSetCommand(); myAccessDataSetCmd.SelectCommand = new ADOCommand(strAccessSelect,myAccessConn); myAccessConn.Open(); try { myAccessDataSetCmd.FillDataSet(myDataSet,"Categories"); } finally { myAccessConn.Close(); } try { /* A dataSet can contain multiple tables, so let's get them all into an array */ DataTable[] dta = myDataSet.Tables.All; foreach (DataTable dt in dta) { Console.WriteLine("Found data table {0}", dt.TableName); }
/* The next two lines show two different ways you can get the count of tables in a dataset */ Console.WriteLine("{0} tables in data set", myDataSet.Tables.Count); Console.WriteLine("{0} tables in data set", dta.Length); /* The next several lines show how to get information on a specific table by name from the dataset */ Console.WriteLine("{0} rows in Categories table", myDataSet.Tables["Categories"].Rows.Count); /* The column info is automatically fetched from the database, so we can read it here */ Console.WriteLine("{0} columns in Categories table", myDataSet.Tables["Categories"].Columns.Count); DataColumn[] drc = myDataSet.Tables["Categories"].Columns.All; int i = 0; foreach (DataColumn dc in drc) { /* Print the column subscript, then the column's name and its data type */ Console.WriteLine("Column name[{0}] is {1}, of type {2}",i++ , dc.ColumnName, dc.DataType); } DataRow[] dra = myDataSet.Tables["Categories"].Rows.All; foreach (DataRow dr in dra) { /* Print the CategoryID as a subscript, then the CategoryName */ Console.WriteLine("CategoryName[{0}] is {1}", dr[0], dr[1]); } } catch (Exception e) { Console.WriteLine("Oooops. Caught an exception:\n{0}", e.Message); } } }这段ADO代码示例,是在控制台下运行不说,也并不容易读懂,我除了连接串“Provider=Microsoft.Jet.OLEDB.4.0;Data Source=BugTypes.MDB”还有SQL语句外,一看其他的头都大了!
Public Class HelloWorld
Public Shared Sub Main()
System.Console.WriteLine("Hello World")
End Sub
End Class
那你就买张visual.net吧。
class HelloCSharp
{
static void Main()
{
Console.WriteLine("Hello C# !");
Console.ReadLine();
}
} 多加一行Console.ReadLine(); 省得在控制台站不住,就象原先在C里用getchar();一样
using System.Data;
using System.Data.ADO;public class MainClass
{
public static void Main ()
{
// set Access connection and select strings
string strAccessConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=BugTypes.MDB";
string strAccessSelect = "SELECT * FROM Categories"; //Create the dataset and add the Categories table to it
DataSet myDataSet = new DataSet();
myDataSet.Tables.Add("Categories");
// create my Access objects
ADOConnection myAccessConn = new ADOConnection(strAccessConn);
ADODataSetCommand myAccessDataSetCmd = new ADODataSetCommand();
myAccessDataSetCmd.SelectCommand = new ADOCommand(strAccessSelect,myAccessConn); myAccessConn.Open();
try
{
myAccessDataSetCmd.FillDataSet(myDataSet,"Categories");
}
finally
{
myAccessConn.Close();
} try
{
/* A dataSet can contain multiple tables,
so let's get them all into an array */
DataTable[] dta = myDataSet.Tables.All;
foreach (DataTable dt in dta)
{
Console.WriteLine("Found data table {0}", dt.TableName);
}
/* The next two lines show two different ways
you can get the count of tables in a dataset */
Console.WriteLine("{0} tables in data set", myDataSet.Tables.Count);
Console.WriteLine("{0} tables in data set", dta.Length);
/* The next several lines show how to get information
on a specific table by name from the dataset */
Console.WriteLine("{0} rows in Categories table", myDataSet.Tables["Categories"].Rows.Count);
/* The column info is automatically fetched from the
database, so we can read it here */
Console.WriteLine("{0} columns in Categories table", myDataSet.Tables["Categories"].Columns.Count);
DataColumn[] drc = myDataSet.Tables["Categories"].Columns.All;
int i = 0;
foreach (DataColumn dc in drc)
{
/* Print the column subscript, then the
column's name and its data type */
Console.WriteLine("Column name[{0}] is {1}, of type {2}",i++ , dc.ColumnName, dc.DataType);
}
DataRow[] dra = myDataSet.Tables["Categories"].Rows.All;
foreach (DataRow dr in dra)
{
/* Print the CategoryID as a subscript,
then the CategoryName */
Console.WriteLine("CategoryName[{0}] is {1}", dr[0], dr[1]);
}
}
catch (Exception e)
{
Console.WriteLine("Oooops. Caught an exception:\n{0}", e.Message);
}
}
}这段ADO代码示例,是在控制台下运行不说,也并不容易读懂,我除了连接串“Provider=Microsoft.Jet.OLEDB.4.0;Data Source=BugTypes.MDB”还有SQL语句外,一看其他的头都大了!
网上有的是呀,