gpt4 book ai didi

c# - 在用户和服务器之间传递数据

转载 作者:太空宇宙 更新时间:2023-11-03 16:09:58 25 4
gpt4 key购买 nike

我正在尝试通过 restsharp 将数据从用户传输到服务器并返回。以下是我使用过的代码。我收到一条错误消息“当前上下文中不存在名称‘InitializeComponent’”

我该如何调试它?有逻辑错误吗?

'using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using RestSharp;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Linq;


namespace Miser_sApp
{
public class RestSharp
{
public partial class SearchResults : PhoneApplicationPage
{
public static float _latitude, _longitude;
public static DateTime _date, _time;
public static string _name, _details;
public static int _number, _amount, _uid;
RestClient client;
RestRequest request;

int index;
connect Connect;
public SearchResults()
{
InitializeComponent();
load();

}
private RestClient InitializeX()
{
var client = new RestClient("//localhost" + Panorama1.username1 + "&pro_type=" + Panorama1.number1 + "&pro_name=" + Panorama1.details1 + "&lat=" + Panorama1.lat1 + "&lon=" + Panorama1.lon1);
return client;
// request = new RestRequest(Method.GET);
}
public void load()
{
client = InitializeX();
//MessageBox.Show("InternalInitialize Done");
request = new RestRequest(Method.POST);

client.ExecuteAsync<connect>(request, (response) =>
{
// MessageBox.Show(response.Data.ToString());
Connect = response.Data;
if (response.Data == null || Connect.last == null || Connect == null)
{
MessageBox.Show("NO ITEMS FOUND");
NavigationService.Navigate(new Uri("/Personal.xaml", UriKind.Relative));

}
// name1.Items.Add(rootObject3.Details[0].ProductName);
//results.Items.Clear();
//int i = 0;
else
foreach (var row3 in Connect.last)
{
results.Items.Add("NAME-" + row3.Name + '\n' + "Details-" + row3.Details + '\n' + "Date-" + row3.Date + '\n' + "Amount-" + row3.Amount + '\n' + "userId-" + row3.Uid + '\n' + "---------------------------------------------------------------");
}
});

}




private void Button_Click(object sender, RoutedEventArgs e)
{

Konnect d = Connect.last[index];
_name = d.Name;
_date = d.Date;
_time = d.Time;
_uid = d.Uid;
_amount = d.Amount;
_details = d.Details;
_latitude = d.Latitude;
_longitude = d.Longitude;

NavigationService.Navigate(new Uri("/Panaroma1.xaml", UriKind.Relative));


}

private void results_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
index = results.SelectedIndex;
}

}
public class Konnect
{
public string Name { get; set; }
public DateTime Date { get; set; }
public DateTime Time { get; set; }
public int Uid { get; set; }
public String Details { get; set; }
public int Amount { get; set; }
public float Latitude { get; set; }
public float Longitude { get; set; }
}

public class connect
{
public List<Konnect> last { get; set; }
}

}
}

最佳答案

这意味着 InitializeComponent();方法不存在。在下面的代码中。这可能是一个引用问题。这也可能意味着设计器文件有问题,因为设计器支持需要它。您可以在运行调试器时尝试进入该方法。还有错误发生在哪里?它是运行时错误还是在您尝试编译时发生?如果是编译错误,则意味着该方法不存在,您需要创建它或删除该方法中的引用。

public SearchResults()
{
InitializeComponent();
load();

}

编辑:

您可能在 designer.cs 文件中遗漏了这一部分。请注意,这是基于一个 win 表单应用程序。您将需要研究此方法在您尝试继承的类中的位置。即 PhoneApplicationPage 类

    #region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Text = "Form1";
}
#endregion

我刚刚创建了一个新应用,它自动为我生成了这个。您必须删除它或其他内容。

关于c# - 在用户和服务器之间传递数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17847771/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com