我用mysql存储空间数据,在mysql中自己写入sql语句,插入也好,查询也好,都是正常。。
比如:CREATE TABLE geom (g GEOMETRY);
INSERT INTO geom VALUES (GeomFromText('POINT(1 1)'));以上是创建含有空间数据类型的列,并加入一个点类型的数据。。SELECT AsText(g) FROM geom;查询该表中这一列的值,能够在mysql中正常显示,显示结果为POINT(1 1)。我想在C#中连接mysql数据库并读取,但是失败,
我的C#代码如下:
string query = "select Astext(g) from geom";
        MySqlConnection myConnection = new MySqlConnection("server=localhost;user id=root;password=fc;database=test");
        MySqlCommand myCommand = new MySqlCommand(query, myConnection);
        myConnection.Open();
        myCommand.ExecuteNonQuery();
        MySqlDataReader myDataReader = myCommand.ExecuteReader();
        string bookres = "";
        while (myDataReader.Read() == true)
        {
            bookres += myDataReader["Astext(g)"];          
        }
        myDataReader.Close();
        myConnection.Close();
我的问题在于myDataReader["Astext(g)"]读取出来的永远都是system.byte[]这样一个字符串不知道问题出在哪儿??。请高手帮忙。。
谢谢~~~

解决方案 »

  1.   

    我自己搞定了换了别的数据库连接用的是using MySQLDriverCS;代码也改正如下:
    MySQLConnection conn = null;        conn = new MySQLConnection(new MySQLConnectionString("localhost", "test", "root", "fc").AsString);        conn.Open();        MySQLCommand commn = new MySQLCommand("set names gb2312", conn);        commn.ExecuteNonQuery();        string sql = "select ID,Astext(g) from geom where ID='111'";        MySQLDataAdapter mda = new MySQLDataAdapter(sql, conn);        DataSet ds = new DataSet();        mda.Fill(ds, "table1");
            ds.Tables["table1"].Rows[0][1].ToString()就是要读取第一行第二列空间数据字段的内容。
      

  2.   

    我自己搞定了. 强![align=center]====  ====
    [/align]