IElement pele = new MarkerElementClass();
IPoint pp = new PointClass();
pp.PutCoords(e.mapX, e.mapY);
pele.Geometry = pp;
IMarkerElement pme = pele as IMarkerElement;
IRgbColor prgb = new RgbColorClass();
prgb.Blue = cc.B;
prgb.Green = cc.G;
prgb.Red = cc.R;
psms.Color = prgb;
pme.Symbol = psms;
pgc.AddElement(pele, 0);
this.axMapControl1.ActiveView.Refresh();
//写入数据库
string scn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=数据表.mdb";
OleDbConnection mycn = new OleDbConnection(scn);
mycn.Open();
OleDbCommand mycmd = new OleDbCommand();
mycmd.Connection = mycn;
mycmd.CommandType = CommandType.Text;
mycmd.CommandText = "select * from point1";
OleDbDataAdapter adap = new OleDbDataAdapter();
adap.SelectCommand = mycmd;
DataSet ds = new DataSet();
adap.Fill(ds, "a");
DataTable dt = new DataTable();
dt = ds.Tables["a"];
string s = DateTime.Now.ToString();
int indext = this.comboBox1.SelectedIndex + 1;
string id = indext.ToString();
int x = Convert.ToInt32(pp.X);
string d = "insert into point1 values('" + id + "'," + x + "," + pp.Y + ",'" + s + "')";
mycmd.CommandText = d;
mycmd.ExecuteNonQuery();
this.dataGridView1.DataSource = ds.Tables[0];
IElement pele = new MarkerElementClass(); //标记元素
IPoint pp = new PointClass(); //点
pp.PutCoords(e.mapX, e.mapY); //将点放在坐标上
pele.Geometry = pp; //标记元素的坐标设置为上面定义的点
IMarkerElement pme = pele as IMarkerElement; //另一个标记
IRgbColor prgb = new RgbColorClass(); //颜色
prgb.Blue = cc.B;//蓝色
prgb.Green = cc.G;//绿色
prgb.Red = cc.R;//红色
psms.Color = prgb;//设置颜色
pme.Symbol = psms;//设置符号
pgc.AddElement(pele, 0);//添加上去
this.axMapControl1.ActiveView.Refresh();//刷新地图
//写入数据库
string scn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=数据表.mdb"; //access数据库文件
OleDbConnection mycn = new OleDbConnection(scn); //创建连接
mycn.Open(); //打开
OleDbCommand mycmd = new OleDbCommand(); //定义查询命令
mycmd.Connection = mycn; //查询关联给连接
mycmd.CommandType = CommandType.Text; //命令类型为sql
mycmd.CommandText = "select * from point1"; //查询所有的point1的数据
OleDbDataAdapter adap = new OleDbDataAdapter(); //数据适配器
adap.SelectCommand = mycmd; //关联给命令
DataSet ds = new DataSet(); //数据集
adap.Fill(ds, "a"); //将结果输出到数据集
DataTable dt = new DataTable(); //表
dt = ds.Tables["a"]; //获取表
string s = DateTime.Now.ToString(); 当前时间
int indext = this.comboBox1.SelectedIndex + 1; //列表框选择+1
string id = indext.ToString(); //id
int x = Convert.ToInt32(pp.X); //坐标x值
string d = "insert into point1 values('" + id + "'," + x + "," + pp.Y + ",'" + s + "')"; //插入到point1表
mycmd.CommandText = d;
mycmd.ExecuteNonQuery(); //执行查询
this.dataGridView1.DataSource = ds.Tables[0]; //绑定表