在RPG程序(AS/400上的IBM语言之一)中,我可以"链接"到文件中以查看文件中是否存在记录(例如,某个客户记录).如果是,那么我可以使用新数据立即更新该记录.如果记录不存在,我可以写一条新记录.代码如下所示:
Customer Chain CustFile 71 ;turn on indicator 71 if not found
if *in71 ;if 71 is "on"
eval CustID = Customer;
eval CustCredit = 10000;
write CustRecord
else ;71 not on, record found.
CustCredit = 10000;
update CustRecord
endif
Run Code Online (Sandbox Code Playgroud)
我不熟悉SQL/C#,我想知道是否有办法从文件中进行随机检索(这就是RPG中的"链").基本上我想看看是否存在记录.如果是,请使用一些新信息更新记录.如果没有,那么我想写一个新的记录.我确信这是可能的,但不太确定如何去做.任何建议将不胜感激.
我正在读一本关于用C#编程ASP.NET的书.这本书做出如下评论:
本书的前几版处理了Web服务,这一功能允许您创建可由Internet上的其他应用程序调用的代码例程.在考虑富客户端开发时,Web服务更有趣(因为它们允许您将Web功能提供给普通桌面应用程序),它们正在被称为WCF(Windows Communication Foundation)的新技术所取代.由于这些原因,本书不涉及Web服务.但是,如果您想分支并探索Web服务世界,可以从本书的下载页面下载本书上一版的Web服务章节.这些章节中的信息仍适用于ASP.NET 3.5,因为Web服务功能尚未更改.
有人可以用"外行人的术语"提供究竟是什么样的网络服务,以及它们是否真的被WCF替换,至少在.Net中?什么是Web服务的实际示例?它们是独立于Web服务器上运行并由客户端或客户端调用的程序吗?
我想在datagridview中获取每一行并将其添加到一个字符串变量,然后我将使用自定义PrintDocument类进行打印.我的程序中的所有内容都可以工作,除了将datagridview中的数据转换为字符串变量.我找不到一个如何做到这一点的例子.我不是只使用"foreach(dataGridView1中的DataRow Row)..."循环数据表并将其添加到我的字符串变量中吗?有人能给我看一个例子吗?
现在,我的代码看起来像这样,但它不会编译(在我尝试从column.row获取值到字符串的方式上获取错误消息.错误消息是"最佳重载方法匹配对于'System.Windows.Form.DataGridViewRowCollection.This [int]'有一些无效的参数):
//Loop through the dataGridView1 and add it to the text
//that we want to print
foreach (DataRow row in dataGridView1.Rows)
{
textToPrint = textToPrint + dataGridView1.Rows[row][0].ToString() + "\t" +
dataGridView1.Rows[row][1].ToString() + "\t" +
dataGridView1.Rows[row][2].ToString() + "\t" +
dataGridView1.Rows[row][3].ToString() + "\t";
}
Run Code Online (Sandbox Code Playgroud) 我看到用C#编写的方法返回一个布尔值.方法的return语句如下所示:
return count > 0;
Run Code Online (Sandbox Code Playgroud)
如果我正确读取它,如果count大于零,它将返回一个值.如果'count'的值不大于0会发生什么?什么回来了?零?如果是这样的话,那么返回声明就不能说:
return count;
Run Code Online (Sandbox Code Playgroud) 我刚刚学习ASP.Net,所以我希望你能忍受我和我的问题.在我的程序中,我有一个数据集,其中包含指向各种图像的Url字符串.我的问题是,我可以将该数据集用作Repeater控件的数据源,以便Repeater使用这些Urls来显示图像吗?
非常感谢任何帮助和建议.
处理一个程序,我需要将三条信息传递给一个方法,该方法将从传入的数据中为表创建一行.
变量是:
var runningTally = new Dictionary<string, Dictionary<string, int>>();
var comments = query.ToList();
var columns = query.ToList();
Run Code Online (Sandbox Code Playgroud)
我会这样调用这个方法:
tReport.Rows.Add(row);
foreach (var key in _masterList.Keys)
{
CreateRow(key, runningTally, columns);
}
Run Code Online (Sandbox Code Playgroud)
我希望我的方法签名看起来像这样:
private void CreateRow(string key, IDictionary<string, Dictionary<string, int>>
runningTally, List<T> columns)
Run Code Online (Sandbox Code Playgroud)
但这不起作用(编辑抱怨无法找到类型'T').我希望有人能告诉我如何正确使用通用列表作为方法的参数.我感谢任何帮助和建议!
我的表格上有一个combobox电话ddCourses.我正在尝试使用LINQ表达式加载它,但是当我运行程序时,combobox它显示我使用LINQ语句加载的值(COURSE_ID)和文本(COURSE_TITLE),而不仅仅是文本(我想要值) ,COURSE_ID,隐藏).
这是我的代码:
private void LoadDropDowns()
{
var db = new DataClasses1DataContext();
ddCourse.DataSource = (from c in db.COURSE_MASTERs
select new { c.COURSE_ID, c.COURSE_TITLE }).ToList();
}
Run Code Online (Sandbox Code Playgroud)
如何设置每行的值和文本combobox?
我见过的其他例子DataTextField和DataValueField属性,但这些似乎不适合我.
我在我的using陈述中遗漏了一个允许我访问DataTextField和DataValueField属性的引用吗?
这是我的"使用"声明:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
Run Code Online (Sandbox Code Playgroud)
编辑:DataTextField和DataValueField属性不可用.这是因为它们是System.Web.UI的一部分,这是我正在使用的winform?
我有一个类clsPerson,看起来像这样:
public class clsPerson
{
public string FirstName;
public string LastName;
public string Gender;
public List<Book> Books;
}
Run Code Online (Sandbox Code Playgroud)
我有另一个类,Book,看起来像这样:
public class Book
{
public string Title;
public string Author;
public string Genre;
public Book(string title, string author, string genre)
{
this.Title = title;
this.Author = author;
this.Genre = genre;
}
}
Run Code Online (Sandbox Code Playgroud)
我编写了一个程序来测试将对象序列化为XML.到目前为止,这就是我所拥有的:
class Program
{
static void Main(string[] args)
{
var p = new clsPerson();
p.FirstName = "Kevin";
p.LastName = "Jennings";
p.Gender = "Male";
var book1 = new Book("Neuromancer", "William …Run Code Online (Sandbox Code Playgroud) 我有一些代码创建了几个Person对象,然后将这些对象添加到List.我试图通过使用输出属性和值到控制台TypeDescriptor.GetProperties().不过,我没有得到任何输出.当我在调试中单步执行时,描述符foreach循环就像我的Person对象中没有属性一样.但是,当我在调试中查看对象时,我可以看到对象的所有属性,它们都有值(即name ="Mark",age ="40"等).有人告诉我为什么它不起作用,显然,我的对象中有属性和值?
这是我用于此特定部分的代码:
foreach (var person in People)
{
foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(person))
{
string name = descriptor.Name;
object value = descriptor.GetValue(person);
Console.WriteLine("{0}={1}", name, value);
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:这是我正在修补的课程和程序.基本上只是一个程序,您可以将特定的XML文件拖放到表单中,目的是将对象的属性及其值打印到控制台.
这是我的Person类:
namespace WindowsFormsApplication5
{
public class Person
{
//Must have zero parameter constructor for Object => XML serialization.
public Person(){}
public Person(string name, int age, string gender, bool hasChildren,
List<Person> children = null )
{
Name = name;
Age = age;
Gender = gender; …Run Code Online (Sandbox Code Playgroud) 另一个程序是通过我的程序一个对象列表.这些对象具有一个名为的属性Title,在此列表中,其中一个对象将具有与第一个对象的标题匹配的标题.我想将此列表分成两个列表,使用与第一个具有相同标题的第二个对象作为标志,将剩余对象写入另一个列表.我写了一个小例子程序,表明我想要完成的事情.我希望有人可以指出我正确的方向.
static void Main(string[] args)
{
var names = new string[] {"Frank", "Jules", "Mark", "Allan", "Frank", "Greg", "Tim"};
var listA = new List<string>();
var listB = new List<string>();
foreach (var name in names)
{
// Add all names to listA, until name is the next "Frank".
// If name is the next "Frank" add name and all remaining
// names to listB.
// So, listA would contain "Frank", "Jules", "Mark", "Allan"
// listB would contain "Frank", "Greg", "Tim" …Run Code Online (Sandbox Code Playgroud) 我知道我错过了什么,但我有限的经历阻碍了我.有什么建议?谢谢你的帮助!
页码:
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<asp:Image runat="server" ID="image1" ImageUrl="<%# DataBinder.Eval(Container.DataItem, "url") %>" />
</ItemTemplate>
</asp:Repeater>
Run Code Online (Sandbox Code Playgroud)
代码背后:
protected void Page_Load(object sender, EventArgs e)
{
var dt = new DataTable("images");
dt.Columns.Add("url");
dt.Rows.Add("http://www.boeing.com/assets/images/defense-space/military/p8a/images/P8-A_index.jpg");
dt.Rows.Add("http://www.tractorbynet.com/forums/attachments/power-trac/258427d1333048884-p-8-replacing-p3c-p-8a_mma_changed_wing_lg.jpg");
var ds = new DataSet();
ds.Tables.Add(dt);
Repeater1.DataSource = ds.Tables[0];
Repeater1.DataBind();
}
Run Code Online (Sandbox Code Playgroud)
错误:

我的程序创建一个列表,用Person对象填充它,并尝试查找与列表中第一个对象同名的下一个对象的索引.知道该特定索引的位置,程序可以将原始列表拆分为两个不同的列表.但是,出于某种原因,LINQ表达式返回零,splitLocation因为我希望它返回值为5.显然,我正在做LINQ表达式错误,或者我不理解我应该如何使用它FindIndex.这是我的代码:
using System.Collections.Generic;
using System.Linq;
namespace NeedleInHaystack
{
class Program
{
static void Main(string[] args)
{
// create the 'haystack'
var people = new List<Person>();
var person1 = new Person("Frank");
var person2 = new Person("Jules");
var person3 = new Person("Mark");
var person4 = new Person("Allan");
var person5 = new Person("Frank");
var person6 = new Person("Greg");
var person7 = new Person("Tim");
people.Add(person1);
people.Add(person2);
people.Add(person3);
people.Add(person4);
people.Add(person5);
people.Add(person6);
people.Add(person7);
// here's the …Run Code Online (Sandbox Code Playgroud) 可能重复:
C#字符串格式化和填充
在我的C#程序中,我有四个变量:
string checkNo = "1234";
string checkAmount = "25.60";
string checkCashedDate = "120413";
string filler = " "; // three spaces
Run Code Online (Sandbox Code Playgroud)
我想构建一个字符串(长26个位置),如下所示:
"00123400000002560120413 "
Run Code Online (Sandbox Code Playgroud)
我可以手动执行,即检查每个字段的长度(删除小数),使用适当数量的零填充,附加到最终字符串.但是,我希望有更快的方法.就像创建一个具有特定格式(全为零)的字符串然后"插入"值.C#中有这样的东西吗?感谢您的帮助和建议.