我在DataSet中有一个表,我想使用唯一键在此表中搜索一行.
我的问题是:有没有任何方法可以让我在不使用循环的情况下找到这一行?
这是我使用forech循环编写的代码:
foreach (var myRow in myClass.ds.Tables["Editeur"].AsEnumerable())
{
if (newKeyWordAEditeurName == myRow[1] as String)
id_Editeur_Editeur = (int)myRow[0];
}
Run Code Online (Sandbox Code Playgroud) 我试图在SQL DB的表中添加新行,但是遇到了一个问题:
多个基本表不支持动态SQL生成
这是我尝试的代码:
private MyClass myClass = new MyClass();
private SqlDataAdapter adapter;
private SqlDataAdapter adapter2;
private void GestionCollections_Load(object sender, EventArgs e)
{
adapter = new SqlDataAdapter("select Id_Collection ID, Libelle_Collection Collection,Libelle_Editeur Editeur from Collection_ left join Editeur on Id_Editeur = Collection_.Id_Editeur_Editeur", myClass.cnx);
adapter.Fill(myClass.ds, "Collection_");
adapter2 = new SqlDataAdapter("Select Id_Editeur ID,Libelle_Editeur Editeur from Editeur", myClass.cnx);
adapter2.Fill(myClass.ds, "Editeur");
}
private void AjouterBarButton_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
String newKeyWordCollectionName = ajoutCollection.KeyWordCollectionName;
String newKeyWordAEditeurName = ajoutCollection.KeyWordEditeurName;
DataRow row = myClass.ds.Tables["Collection_"].NewRow();
row[1] = newKeyWordCollectionName;
foreach(var …
Run Code Online (Sandbox Code Playgroud) 我创建了一个UserControl,当我点击某个按钮将这个UserControl显示到我的表单中时我想要.
有没有办法做到这一点?
我想运行我的程序在My Documents中为它创建一个默认文件夹,以便第一次使用这个应用程序(如果已存在同名目录,那么我想保留这个文件夹).
这是我到目前为止尝试的代码:
string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
System.IO.Directory.CreateDirectory(path + @"\MaBib");
Run Code Online (Sandbox Code Playgroud) 我试图找到一种快速的方法来在DataTable中的列中查找字符串并将其添加到comboBox,这是我到目前为止尝试的代码:
adapter = new SqlDataAdapter("Select Id_Editeur ID,Libelle_Editeur Editeur from Editeur", myClass.cnx);
adapter.Fill(myClass.ds, "Editeur");
foreach (String str in myClass.ds.Tables["Editeur"].Columns[1].ToString())
editeurBox.Properties.Items.Add(str);
Run Code Online (Sandbox Code Playgroud)
这不起作用它给了我这个错误:
foreach语句不能对'System.Data.DataColumn'类型的变量进行操作,因为'System.Data.DataColumn'不包含'GetEnumerator'的公共定义
我怎样才能做到这一点 ?(我不想要for循环解决方案).
我一直在研究一些代码.我有一个问题:
这两个代码有什么区别?
using (FORM formExemple = new FORM ())
{
formExemple.ShowDialog();
}
Run Code Online (Sandbox Code Playgroud)
和
FORM formExemple = new FORM ();
formExemple.ShowDialog();
Run Code Online (Sandbox Code Playgroud) 我有一个登录表单和一个按钮,用于检查用户名和密码是否为真.但问题是我试过的代码..我必须点击连接按钮两次.
但是当我单击按钮一次时,代码应该可以工作!对 ?
我认为问题是:如果只是点击某个按钮,它的DialogResult设置了某个值,showDialog就不会消失,所以在第一次点击时,connexionButton.DialogResult获取DialogResult.OK值,然后在第二次点击按钮执行代码.
*您可以注意到事件simpleButton1_Click是connexionButton Button的事件*
这是我用过的事件:
this.connexionButton.Click += new System.EventHandler(this.simpleButton1_Click);
Run Code Online (Sandbox Code Playgroud)
这是我试过的代码:
private void simpleButton1_Click(object sender, EventArgs e)
{
Boolean allowCnx = false;
foreach (var row in myClass.ds.Tables["Users"].AsEnumerable())
{
if (row[1].ToString().ToLower() == idBox.Text.ToLower() && row[2].ToString().ToLower() == mdpBox.Text.ToLower())
{
allowCnx = true;
}
}
if (allowCnx)
{
connexionButton.DialogResult = DialogResult.OK;
}
else
XtraMessageBox.Show("Invalide Information", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
Run Code Online (Sandbox Code Playgroud)
这是我用来调用此登录表单的代码:
using (login loginForm = new login())
{
var result = loginForm.ShowDialog();
if (result == DialogResult.OK)
this.Show();
else
this.Close();
}
Run Code Online (Sandbox Code Playgroud)