我尝试从1到100随机生成数字.如何更改随机6位数?
注意:数字不能以0(零)开头
随机1到100个代码
#import <UIKit/UIKit.h>
@interface RandomNumberGenViewController : UIViewController {
int number;
IBOutlet UILabel *label;
}
-(IBAction)generateNumber:(id)sender;
@end
@implementation RandomNumberGenViewController
-(IBAction)generateNumber:(id)sender {
number = (arc4random()%100)+1; //Generates Number from 1 to 100.
NSString *string = [NSString stringWithFormat:@"%i", number];
label.text = string
}
Run Code Online (Sandbox Code Playgroud)

我尝试从excel文件加载gridview.但是我得到了这个错误
Microsoft Jet数据库引擎'Sheet1 $'找不到该对象.确保对象存在且其名称拼写正确且路径正确.
并且此行中存在错误:excelDataAdapter.Fill(dt);
我在App_Data文件夹中有一个.xls文件
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.IO;
using System.Data;
using System.Data.OleDb;
namespace Excell
{
public partial class LoadExcelToGrid: System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
gv.DataSource = exceldata(Server.MapPath("~/data.xls"));
gv.DataBind();
}
public static DataSet exceldata(string filelocation)
{
DataSet ds = new DataSet();
OleDbCommand excelCommand = new OleDbCommand(); OleDbDataAdapter excelDataAdapter = new
OleDbDataAdapter();
string excelConnStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + filelocation +
"; Extended Properties=Excel 8.0;";
OleDbConnection excelConn = …Run Code Online (Sandbox Code Playgroud) 我有一个 Web 服务。此服务将某些客户端的数据插入到 sql 中。我尝试将插入的行和任何异常写入 txt 文件。
void WriteLog(string Log)
{
string FileName= "D:\\MyLogs.txt";
StreamWriter obj;
obj= new StreamWriter(FileName);
obj.WriteLine(DateTime.Now.ToString() + " " + Log);
obj.Close();
}
int row;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString);
SqlCommand cmd = new SqlCommand();
[WebMethod]
public int InsertTable(int Age) {
try {
con.Open();
cmd.CommandText=@"Insert into Table(Age) values(@Age)";
cmd.Parameters.Add(new SqlParameter("Age", SqlDbType.Int, 32, "Age"));
cmd.Parameters["Age"].Value = Age;
cmd.Connection = con;
cmd.ExecuteNonQuery();
row = cmd.ExecuteNonQuery();
WriteLog(row.ToString());
}
catch (Exception ex) {
WriteLog(ex.ToString());
}
finally {
con.Close();
con.Dispose();
cmd.Dispose(); …Run Code Online (Sandbox Code Playgroud) 我尝试从datatable绑定标签
我收到这个错误
Incorrect syntax near '='.
Run Code Online (Sandbox Code Playgroud)
在这条线上
da.Fill(dt);
Run Code Online (Sandbox Code Playgroud)
我的代码:Page_Load
LbLID.Text =this.Page.Request.QueryString["DI"].ToString();
SqlConnection con = new SqlConnection("Data Source=local;Initial Catalog=DB;User
ID=sa;Password="pass);
SqlDataAdapter da = new SqlDataAdapter("select * from Table1 where ID= " +
LbLID.Text.Trim(), con);
System.Data.DataTable dt = new System.Data.DataTable();
da.Fill(dt);
lblS1.Text = dt.Rows[0][4].ToString();
lblS1.DataBind();
Run Code Online (Sandbox Code Playgroud) 我试着在谷歌地图上计算卡车标记的距离.
var Total=0;
var json = result.d;
obj = JSON.parse(json);
for (var i = 0; i < obj.length; i++)
{
var LatLng1 = new google.maps.LatLng(obj[i].Lat, obj[i].Lng);
var LatLng2 = new google.maps.LatLng(obj[i+1].Lat, obj[i+1].Lng);
var Distance=(google.maps.geometry.spherical.computeDistanceBetween(LatLng1, LatLng2) / 1000).toFixed(2);
Total+=Distance;
alert(Total); //It is working but.Like this : 0.01 0.22 0.03 0.045
// I want to be 0.01+0.022+0.03+....=Total
}
alert(Total); //Does not working !!
Run Code Online (Sandbox Code Playgroud)
我在控制台遇到此错误: TypeError: obj[(i + 1)] is undefined.
我哪里错了?