从SQL Server表中读取行

时间:2015-10-04 15:00:25

标签: c# sql-server

此代码仅读取ID 1,我需要读取所有表。我怎么能这样做呢?

lapply(df, transform, numSubStrings=length(strsplit(df$Strings,";")[[1]]))

2 个答案:

答案 0 :(得分:0)

要回答您的直接问题:您需要执行foreach循环,如下所示:

DocumentCompleted

解释使用async void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { if (e.Url.AbsoluteUri != "https://www.onegov.nsw.gov.au/PublicRegister/#/publicregister/search/Security") return; await Task.Delay(5000); var f = this.webBrowser1.Document.Body.All.GetElementsByName("searchForm") .Cast<HtmlElement>() .FirstOrDefault(); var q = f.All.GetElementsByName("searchText") .Cast<HtmlElement>() .FirstOrDefault(); q.InnerText = "123456789"; f.InvokeMember("submit"); } 方法:

类型为using System.Threading.Tasks;的{​​{1}}实现了较旧的IEnumerable接口,该接口枚举了行但是将行作为System.Threading.Thread.Sleep(5000)类型的对象而不是{{1 }}。我们使用Cast方法将它们转换为foreach (var row in table.Rows.Cast<DataRow>()) { var name = row["Name"]; //Continue here }

答案 1 :(得分:0)

如果您正在尝试查找是否存在具有特定名称的用户,那么您不需要阅读整个表,但是您可以编写一个查询,发现是否存在具有该名称的用户

using (SqlConnection sqlConnection = new SqlConnection())
using (SqlCommand sqlCommand = new SqlCommand())
{
    sqlConnection.ConnectionString = "....."";
    sqlCommand.Connection = sqlConnection;
    sqlCommand.CommandText = @"SELECT COUNT(*) FROM dbo.Users 
                        WHERE Name = @name";
    sqlConnection.Open();
    sqlCommand.Parameters.Add("@name", SqlDbType.NVarChar).Value = textBox2.Text;
    int result = Convert.ToInt32(sqlCommand.ExecuteNonQuery());
    if(result > 0) 
        MessageBox.Show("Founded " + result + " user/s");
    else
        MessageBox.Show("No user found with that name");
}