在下一个示例中,我如何知道当前行索引?
foreach (DataRow temprow in temptable.Rows)
{
//this.text = temprow.INDEX????
}
Run Code Online (Sandbox Code Playgroud) 为什么我不能这样做:
usuariosEntities usersDB = new usuariosEntities();
foreach (DataGridViewRow user in dgvUsuarios.Rows)
{
var rowtoupdate =
usersDB.usuarios.Where(
u => u.codigo_usuario == Convert.ToInt32(user.Cells[0].Value)
).First();
rowtoupdate.password = user.Cells[3].Value.ToString();
}
usersDB.SaveChanges();
Run Code Online (Sandbox Code Playgroud)
并且必须这样做:
usuariosEntities usersDB = new usuariosEntities();
foreach (DataGridViewRow user in dgvUsuarios.Rows)
{
int usercode = Convert.ToInt32(user.Cells[0].Value);
var rowtoupdate =
usersDB.usuarios.Where(u => u.codigo_usuario == usercode).First();
rowtoupdate.password = user.Cells[3].Value.ToString();
}
usersDB.SaveChanges();
Run Code Online (Sandbox Code Playgroud)
我必须承认它是一个更易读的代码,但为什么不能这样做呢?
例如,我需要一种方法来禁用表单中的所有按钮或验证所有文本框的数据.有任何想法吗?提前致谢!
我有两个项目:Inventario,Produccion Dampers和我说Inventario作为一个参考Produccion Dampers.当我发布时,Produccion Dampers我没有收到错误,但是当我尝试安装时,我收到此错误:
Following errors were detected during this operation.
* [2/11/2010 3:33:34 PM] System.Deployment.Application.InvalidDeploymentException (RefDefValidation)
- Reference in the manifest does not match the identity of the downloaded assembly Inventario.exe.
- Source: System.Deployment
- Stack trace:
at System.Deployment.Application.DownloadManager.ProcessDownloadedFile(Object sender, DownloadEventArgs e)
at System.Deployment.Application.FileDownloader.DownloadModifiedEventHandler.Invoke(Object sender, DownloadEventArgs e)
at System.Deployment.Application.SystemNetDownloader.DownloadSingleFile(DownloadQueueItem next)
at System.Deployment.Application.SystemNetDownloader.DownloadAllFiles()
at System.Deployment.Application.FileDownloader.Download(SubscriptionState subState)
at System.Deployment.Application.DownloadManager.DownloadDependencies(SubscriptionState subState, AssemblyManifest deployManifest, AssemblyManifest appManifest, Uri sourceUriBase, String targetDirectory, String group, IDownloadNotification …Run Code Online (Sandbox Code Playgroud) 您好我想用一般方法添加控件到我的表单,如下所示:
void addcontrol(Type quien)
{
this.Controls.Add(new quien);
}
private void btnNewControl_Click(object sender, EventArgs e)
{
addcontrol(typeof(Button));
}
Run Code Online (Sandbox Code Playgroud)
这可能吗?
我想使用L2E,因为它对我公司的应用非常方便,我创建了一个演示项目,演示确实在每台机器上运行但是当我说,按下一个按钮,其中包含一些使用该实体的代码我得到了这个错误:
specified store provider cannot be found in the configuration, or is not valid.
Run Code Online (Sandbox Code Playgroud)
请注意,我只在没有安装VS2008的机器上得到此错误,在这些机器上(VS2008的机器),该演示效果很好.任何建议表示赞赏.
我正在使用MySql服务器与Mysql Conector 6.3,并使用ADO.Net权利模型创建模型.
编辑
这是完整的错误跟踪:
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.ArgumentException: The specified store provider cannot be found in the configuration, or is not valid. ---> System.ArgumentException: Unable to find the requested .Net Framework Data Provider. It may not be installed.
at System.Data.Common.DbProviderFactories.GetFactory(String providerInvariantName)
at System.Data.EntityClient.EntityConnection.GetFactory(String providerString)
--- …Run Code Online (Sandbox Code Playgroud) 我厌倦了写作,x > min && x < max所以我想写一个简单的函数,但我不确定我是否做得对...实际上我不是因为我得到一个错误:
bool inBetween<T>(T x, T min, T max) where T:IComparable
{
return (x > min && x < max);
}
Run Code Online (Sandbox Code Playgroud)
错误:
Operator '>' cannot be applied to operands of type 'T' and 'T'
Operator '<' cannot be applied to operands of type 'T' and 'T'
Run Code Online (Sandbox Code Playgroud)
我可能where对函数声明中的部分有一个不好的理解
注意:对于那些打算告诉我我将编写比以前更多的代码的人...想想可读性=)任何帮助将不胜感激
编辑
删除因为它被解决了=)
另一个编辑
所以在经过一番头痛之后,我在@Jay极端可读性的想法之后出现了这个(嗯)的事情:
public static class test
{
public static comparision Between<T>(this T a,T b) where T : IComparable
{
var ttt …Run Code Online (Sandbox Code Playgroud) c# ×10
winforms ×7
controls ×2
.net ×1
containers ×1
deployment ×1
foreach ×1
forms ×1
generics ×1
linq ×1
mysql ×1
publishing ×1
wizard ×1