小编SHE*_*ETE的帖子

如何使用C#处理401错误响应?

我有一个API返回的json response.当我打电话APIFiddler它时,它给我json reponse 如下所示:

在此输入图像描述

JSON响应: 在此输入图像描述

从网页调用API:

protected void FinalCall()
    {

       // try
       // {
            string url = txtdomainURL.Text.Trim(); 
            string apiname = txtAPIname.Text.Trim();
            string apiURL = apiname+"/"+txtStoreID.Text.Trim()+"/"+txtSerialNo.Text.Trim(); //"duediligence/1/45523354232323424";// 990000552672620";//45523354232323424";
            //duediligence/1/45523354232323424 HTTP/1.1
            string storeID = txtStoreID.Text.Trim();//Test Store ID:1 Live Store ID: 2
            string partnerID = txtPartnerID.Text.Trim();// "1";
            string scretKey = txtSecretKey.Text.Trim();// "234623ger787qws3423";
            string requestBody = txtRequestBody.Text.Trim(); //"{\"category\": 8}";
            string data = scretKey + requestBody;


            string signatureHash = SHA1HashStringForUTF8String(data);
            lblSignatureHash.Text = signatureHash;
            String userName …
Run Code Online (Sandbox Code Playgroud)

c# asp.net json exception-handling http-status-code-401

3
推荐指数
1
解决办法
7088
查看次数

错误:.net中的db.SaveChanges()发生参照完整性约束违规?

我创建了一个WPF应用程序,Entity framework 4.0.当我试图在PhoneNumber表中插入记录时,它成功地插入了第一条记录.但是,当我遍历一些List并尝试将另一个项插入PhoneNumber表时,它插入记录但显示错误为:

InvalidOperationException由用户代码处理:对数据库的更改已成功提交,但更新对象上下文时发生错误.ObjectContext可能处于不一致状态.内部异常消息:发生了引用完整性约束违规:定义引用约束的属性值在关系中的主体和从属对象之间不一致.

.cs文件中的代码:

protected void InsertContact(List<PhoneNumbersList> phoneList,otherparameters here)
{
             Contact contact = new Contact();
             PhoneNumber phnumber = new PhoneNumber();

            //INSERT into Contacts Table
            contact.PrefixTitleID = cfnm.PrefixTitleID;// cfnm.Title;
            contact.FirstName = cfnm.FirstName;
            contact.MiddleName = cfnm.MiddleName;
            contact.LastName = cfnm.LastName;
            contact.Website = webpageaddress;
            contact.SuffixID = cfnm.SuffixID;
            contact.Gender = gender;
            contact.IMAddress = imaddress;

            db.Contacts.Add(contact);
            db.SaveChanges();
            int contactid=contact.ContactID;
            if (contactid > 0)
            {
                int phid = 0;
                //INSERT into PhoneNumber Table
                foreach (var ph in phoneList)
                {

                    phnumber.PhoneTypeID …
Run Code Online (Sandbox Code Playgroud)

.net entity-framework invalidoperationexception foreign-key-relationship

2
推荐指数
1
解决办法
5020
查看次数

我们可以使用Linq将匿名类型转换为List <T>到C#中的实体吗?

我有一个包含三列的表我想使用自联接并检索具有别名的列.

表:Material(ID,Name,MaterialParentID)

public List<Material> GetMaterialList()
{
    List<Material> materilaList = new List<Material>();
    var query = (from c1 in db.Materials
                 join c2 in db.Materials on c1.ID equals c2.MaterialParentID
                 select c2);        

    return query.ToList();
}
Run Code Online (Sandbox Code Playgroud)

我想在exisiting查询中添加以下内容并返回List

select new { c2.ID, c2.MaterialParentID, c2.Name, ParentName = c1.Name })
Run Code Online (Sandbox Code Playgroud)

c# linq-to-entities

2
推荐指数
1
解决办法
6903
查看次数

如何将过滤器应用于具有多个“ AND”条件的DataView

我有一个DataTable包含一些行。复制到DataView。现在,我有ID的形式List<string>。其中包含从中选择的项目GridView。现在,我想DataView使用AND作为过滤器对此进行过滤。

当我只应用一个时,它起作用,但是应用多个时,AND则不起作用。

在.cs中:

List<string> selectedAddress = new List<string>();
protected DataView GetSelectedItems()
{
    DataView dv = new DataView(dtresult);
    int count = selectedAddress.Count();
    if (count > 0)
    {
        string query = "ID=";

        for (int j = 0; j < selectedAddress.Count; j++)
        {
            string val = selectedAddress[j].ToString();
            if (j == 0)
            {
                query += val + " and ";
            }
            else
            {
                query += "ID=" + val + "";
            }
        } …
Run Code Online (Sandbox Code Playgroud)

c# asp.net dataview filtering rowfilter

2
推荐指数
1
解决办法
3万
查看次数

如何在 C# 中生成字母数字优惠券代码?

我有一个方法可以生成Coupon Code. 任何人都可以帮助/建议生成ALPHANUMERIC CODE吗?

以下是方法:

public string CouponGenerator(int length)
    {
        var sb = new StringBuilder();
        for (var i = 0; i < length; i++)
        {
            var ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * _random.NextDouble() + 65)));

            sb.Append(ch);
        }

        return sb.ToString();
    }
    private static readonly Random _random = new Random();
Run Code Online (Sandbox Code Playgroud)

例子:

UZWKXQML 当 Lenght 设置为 8 时

但它需要像U6WK8Q2Lie 字母数字代码这样的东西。

c# random alphanumeric

2
推荐指数
1
解决办法
5955
查看次数

不正确的字符串值:'\xF0\x9F\x92\x8F\x0A#...对于 mysql 中的列?

我是新手MySQL。我有一列存储Unicode characterMySQL表中。

我有一个代码,它从twitter,facebook等处获取帖子并将text/symbol “原样”插入表中。

CREATE TABLE `tbl_unicode` (
  `_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
  `first_name` varchar(45) NOT NULL,
  `uninoce_Column` varchar(200) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`_id`)

) ENGINE=InnoDB AUTO_INCREMENT=201 DEFAULT CHARSET=utf8;


/* This query WONT work due to SYMBOL:   */
INSERT INTO `tbl_unicode`
  (`_id`,
  `first_name`,
  `uninoce_Column`)
VALUES
  (2,
  'rakesh',
  '?????
#??#??#????#');


/* This query WORKS FINE */
INSERT INTO `tbl_unicode`
  (`_id`,
  `first_name`,
  `uninoce_Column`)
VALUES
  (1,
  'shekhar', …
Run Code Online (Sandbox Code Playgroud)

mysql unicode symbols sql-insert

2
推荐指数
1
解决办法
2618
查看次数

如何将文件复制到特定目录并使用WPF中的OpenDialog设置文件名,扩展名?

我有一个OpenDialog在我的wpf应用程序中,用户可以选择文件并保存到文件夹.我想将图像保存到特定文件夹,并在wpf中单击按钮时设置文件名和扩展名.

文件夹结构:

  • -MyAppDirectory
    --ContactImages

    -1.jpg

当我执行以下代码时,它会ContactImages在Bin文件夹中创建" "目录,而不是在Application main direcotry中.任何的想法?以及如何在wpf和设置文件名中获取上传文件的文件扩展名?

在xaml.cs文件中:

private void imgContactImage_MouseDown(object sender, MouseButtonEventArgs e)
        {

            string folderpath = Environment.CurrentDirectory + "\\ContactImages\\";
            op.Title = "Select a picture";
            op.Filter = "All supported graphics|*.jpg;*.jpeg;*.png|" +
                "JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" +
                "Portable Network Graphic (*.png)|*.png";

            bool? myResult;
            myResult = op.ShowDialog();
            if (myResult != null && myResult == true)
            {

                imgContactImage.Source = new BitmapImage(new Uri(op.FileName));
                if (!Directory.Exists(folderpath))
                {
                    Directory.CreateDirectory(folderpath);
                }

                //System.IO.File.Copy(op.FileName,filename);
            }
}
Run Code Online (Sandbox Code Playgroud)

c# save wpf-controls save-image

1
推荐指数
1
解决办法
6873
查看次数

如何在asp.net中水平并排对齐Div?

我有一个标记,其中包含div一些images如图所示。目前每个部分都是div垂直显示的。但是,我想在屏幕转储中显示左侧的项目和右侧的文本。

HTML 标记:

     <div id="divgetpaidnow" style="float:none;width:200px;" class="paymentclass" paytype="GetPaidNow"  paytypeid="1">
  <asp:Image ID="Image1" src="images/getpaidnow.jpg" runat="server" class="paymentimg" />
   <div>
  </div>
 <asp:RadioButton ID="rdo1" Text="Get Paid Now" runat="server" class="myradio" GroupName="rdoPaymentgroup" />
 <div class="payTypeFooterText" style="float:none;">                                                   <strong>Get Paid Now:</strong><br />
   Instant Cash, visit one of our Mall Locations and get Paid Today
  </div>
 </div>
  <div id="divamazon" style="float: none;" class="paymentclass" paytype="Amazon" paytypeid="2">
     <asp:Image ID="Image2" src="images/amazon.jpg" runat="server" class="paymentimg" />
<div style="margin-top: 10px;">
       </div>
 <asp:RadioButton ID="rdo2" Text="Recommended" runat="server" class="myradio" GroupName="rdoPaymentgroup" />
      <div class="payTypeFooterText">
    <strong>Amazon …
Run Code Online (Sandbox Code Playgroud)

html css asp.net

1
推荐指数
1
解决办法
2万
查看次数

如何从c#中的字符串中删除多余的连字符?

我有一个字符串,其中空格被替换为hyphen i.e '-'如果有多个连字符然后我想从字符串中删除除一个以外的所有.只有连字符必须删除; 不是连续的数字.

例如: - 11-必须是-11-而不是-1-
例如: - 12- o/p:-12-
例如:-12-- o/p:-12-

在C#中使用Linq或字符串函数.

我尝试过使用它str = str.Remove(str.Length - 1);,但它只删除一个字符.

c# linq string

0
推荐指数
1
解决办法
2311
查看次数