日期:2014-05-20  浏览次数:20506 次

新手请教:如何将name字段正常输出(编译器错误消息: CS0029: 无法将类型“string”隐式转换为“int”)
{
  public double[] la = new double[9999];
  public double[] ln = new double[9999];
  public int[] id = new int[9999];
  public string[] name = new string[9999];

  public int k1 = 0;
  public int number;
  protected void Page_Load(object sender, EventArgs e)
  {

  string mycnnConnectionString1=System.Configuration.ConfigurationSettings.AppSettings[ "ConnectionString"].ToString(); //创建连接字符串
  SqlConnection mycnn1 =new SqlConnection(mycnnConnectionString1);
  mycnn1.Open();
  SqlCommand cmd1 = new SqlCommand("select id,lat,lng,name from station ", mycnn1);
  SqlDataReader dr1 = cmd1.ExecuteReader();
  int k2 = 0; 
  int k3 = 0; 
  int k4 = 0;
  string k5 ="" ;
  // string buf1 = ""; 
  double buf2 = 0;
  double buf3 = 0; 
  int buf4 = 0;
  string buf5 = "";
  while (dr1.Read())
  {
  //lat
  buf2 = (double)dr1["lat"];
  la[k2] = buf2;
  k2++;
  //lng
  buf3 = (double)dr1["lng"];///数据库读取float型的数据要用double
  ln[k3] = buf3;
  k3++;
  //id
  buf4 = (int)dr1["id"];
  id[k4] = buf4;
  k4++;
  //name
  buf5 = (string)dr1["name"];
  name[k5] = buf5;
  k5++;
  }
  dr1.Close();
  mycnn1.Close();
  number = k4;
  }
}

------解决方案--------------------
帮你修改过如下
aspx页面
HTML code

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<head id="Head1" runat="server">
    <title>google map</title>
    <script src="http://maps.google.com/maps?file=api&v=2&key=abcdefg"
             type="text/javascript"></script>
     <script type="text/javascript">
     //<![CDATA[

     function load() {
       if (GBrowserIsCompatible()) 
       { 
        
        var map = new GMap2(document.getElementById("map"));  //初始化一个地图实例
        map.addControl(new GLargeMapControl());//全能控件
        map.addControl(new GScaleControl());//比例尺
        map.addControl(new GMapTypeControl());//允许用户在地图类型之间切换
        map.setCenter(new GLatLng(35.745346,114.291375), 12);  //设置地图中心的坐标,中国经纬度及放大倍数
        map.enableDoubleClickZoom();//双击可以放大       
       }
       
         var jingdu= new Array();
         var weidu= new Array();
         var id=new Array();
         var num=new Array("01","01","03","04","05","06","07","08","09");
         var number=<%=number%>;
  <%
   for(int i=0;i<number;i++){
  %> 
   jingdu.push(<%=ln[i]%>);
         weidu.push(<%=la[i]%>);
         id.push(<%=id[i] %>);
  <% 
   }
  %>

var myicon = new GIcon();//创建新图标 
myicon.iconSize = new GSize(27, 27); 
myicon.shadowSize = new GSize(45, 37); 
myicon.iconAnchor = new GPoint(9, 34); 
myicon.infoWindowAnchor = new GPoint(9, 2);
myicon.shadow = "http://google-maps-icons.googlecode.com/files/shadow.png";//指定图标阴影图片
 
<% for(int k1=0;k1<number;k1++){  %>    
    <% if(k1<=8) { %>    
          myicon.image="http://google-maps-icons.googlecode.com/files/red0"+(<%=k1%>+1)+".png ";//指定图标图片
    <% } %>
    
    <% else { %> 
          myicon.image="http://google-maps-icons.googlecode.com/files/red"+(<%=k1%>+1)+".png ";
    <% } %>
 var gPointCZ;
 var gMarkCZ;
    //========================================================================
    gPointCZ=new GLatLng(weidu[<%=k1 %>],jingdu[<%=k1%>]);
 gMarkCZ<%=k1%>=new GMarker(gPointCZ,{icon:myicon,title:"第"+(<%=k1%>+1)+"号点,点击查看更多信息"});
 map.addOverlay(gMarkCZ<%=k1%>);         
    //========================================================================
       
<% } %>
    
     }
     </script>
</head>
<body style="background-color:#F4FFE4" onload="load()" onunload="GUnload()">
   <form id="form1" runat="server">
             <div id="map" style="width: 1200px; height: 500px; position: static;"><!--这里放置地图实例,可以设置显示地图的大小--></div>
    </form>
</body>
</html>