呵呵,以前弄的一个成语字典数据库.最近用C#写了个查询工具.
界面:
源代码如下:
//
http://blog.csdn.net/greenerycn
// 请遵守署名非商业的CC版权.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace CyDict
... {
publicpartialclassForm1:Form
...{
publicForm1()
...{
InitializeComponent();
}
privatevoidForm1_Load(objectsender,EventArgse)
...{
this.reportViewer1.RefreshReport();
}
privatevoidbutton1_Click(objectsender,EventArgse)
...{
//连接数据库
stringcon_str="Provider=Microsoft.Jet.OLEDB.4.0;DataSource=cy.mdb";
//sql语句
stringsql_str="SELECT*FROM[cy]WHERE([成语]=@cy_name)";
OleDbConnectiondb_conn=newOleDbConnection(con_str);
db_conn.Open();
OleDbCommandcm=newOleDbCommand(sql_str,db_conn);
cm.Parameters.Add(newOleDbParameter("@cy_name",OleDbType.Variant,4));
cm.Parameters["@cy_name"].Value=txt_input.Text.Trim();
//查询数据库
OleDbDataReaderreader=cm.ExecuteReader();
if(reader.Read())
...{
string[]result=newstring[9];
result[0]="成语:"+reader["成语"].ToString();
result[2]="解释:"+reader["解释"].ToString();
result[1]="拼音:"+reader["拼音"].ToString();
result[3]="近义:"+reader["近义"].ToString();
result[4]="反义:"+reader["反义"].ToString();
result[5]="出处:"+reader["出处"].ToString();
result[7]="示例:"+reader["示例"].ToString();
result[6]="典故:"+reader["典故"].ToString();
txt_Result.Lines=result;
}
else
...{
txt_Result.Text="无此成语,本词典收录数据6000条!";
}
//不要忘了关闭.
reader.Close();
db_conn.Close();
}
}
}
// 请遵守署名非商业的CC版权.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace CyDict
... {
publicpartialclassForm1:Form
...{
publicForm1()
...{
InitializeComponent();
}
privatevoidForm1_Load(objectsender,EventArgse)
...{
this.reportViewer1.RefreshReport();
}
privatevoidbutton1_Click(objectsender,EventArgse)
...{
//连接数据库
stringcon_str="Provider=Microsoft.Jet.OLEDB.4.0;DataSource=cy.mdb";
//sql语句
stringsql_str="SELECT*FROM[cy]WHERE([成语]=@cy_name)";
OleDbConnectiondb_conn=newOleDbConnection(con_str);
db_conn.Open();
OleDbCommandcm=newOleDbCommand(sql_str,db_conn);
cm.Parameters.Add(newOleDbParameter("@cy_name",OleDbType.Variant,4));
cm.Parameters["@cy_name"].Value=txt_input.Text.Trim();
//查询数据库
OleDbDataReaderreader=cm.ExecuteReader();
if(reader.Read())
...{
string[]result=newstring[9];
result[0]="成语:"+reader["成语"].ToString();
result[2]="解释:"+reader["解释"].ToString();
result[1]="拼音:"+reader["拼音"].ToString();
result[3]="近义:"+reader["近义"].ToString();
result[4]="反义:"+reader["反义"].ToString();
result[5]="出处:"+reader["出处"].ToString();
result[7]="示例:"+reader["示例"].ToString();
result[6]="典故:"+reader["典故"].ToString();
txt_Result.Lines=result;
}
else
...{
txt_Result.Text="无此成语,本词典收录数据6000条!";
}
//不要忘了关闭.
reader.Close();
db_conn.Close();
}
}
}