1.先在项目中导入一个数据库连接类
2.向数据库内编写数据
3.winform设计
4.代码编写
public partial class Form1 : Form
{
Shapefile sf = new Shapefile();
public Form1()
{
InitializeComponent();
//初始化数据库连接
SClass_OledbHelper.Init();
//调用点击
showattribut();
}
public void showattribut()
{
axMap1.SendMouseDown = true;
axMap1.CursorMode = tkCursorMode.cmIdentify;
axMap1.ShapeIdentified += axmapshapeidentified;
}
void axmapshapeidentified(object sender, _DMapEvents_ShapeIdentifiedEvent e)
{
object value = sf.get_CellValue(0, e.shapeIndex);//获取每个探头的id
if (value != null)
{
//sql查询语句,根据日期进行排序,查询最近插入的输入
string sql = "select * from(select t.*,row_number() over(partition by F_ID order by F_DATE desc ) rn from T_DATA t )where rn=1 and F_ID='" + value + "' order by F_ID";
DataTable dt_dba = SClass_OledbHelper.ExecuteDataTable(SClass_OledbHelper.ConnectStringRQGD, CommandType.Text, sql);
if (dt_dba.Rows.Count > 0)//查到到的数据
{
string id = dt_dba.Rows[0][0].ToString();//取查到的数据
string wd = dt_dba.Rows[0][1].ToString();
string sd = dt_dba.Rows[0][2].ToString();
string date = dt_dba.Rows[0][3].ToString();
string ram = dt_dba.Rows[0][4].ToString();
textBox1.Text = id;//进行赋值
textBox2.Text = wd;
textBox3.Text = sd;
textBox4.Text = date;
textBox5.Text = ram;
}
}
}
实现: