我得到這個:選擇列複製另一個
+--------+------+
| id | name |
+--------+------+
| 1 | George |
| 2 | Mathew |
| 3 | Michael |
| 4 | Jones |
+--------+------+
現在我想要做的就是這個。
我想找到我的名字Michael和複製ID「3」邁克爾爲一個字符串變量VS10
我得到這個:選擇列複製另一個
+--------+------+
| id | name |
+--------+------+
| 1 | George |
| 2 | Mathew |
| 3 | Michael |
| 4 | Jones |
+--------+------+
現在我想要做的就是這個。
我想找到我的名字Michael和複製ID「3」邁克爾爲一個字符串變量VS10
你需要下面的查詢選擇從表中id
列,並在指定名稱條件WHERE
條款
Select id from table where name = 'Michael'
如果您在Visual Studio 2010中使用Csharp的,你可以做這樣的事情:
string idValue = String.Empty
string query = " Select id from table where name = 'Michael'";
SqlConnection connection = new SqlConnection(connectionString);
SqlCommand command = new SqlCommand(query, connection);
SqlDataReader reader;
connection.Open();
reader = command.ExecuteReader();
While(reader.Read())
{
idValue = reader["id"].ToString();
}
connection.Close();
return idValue;
在上面的代碼中,idValue
是您要搜索的名稱的id
,而connectionString
是數據庫的連接字符串。
您也可以使用拉姆達這樣的:
string idVal = Table.Where(a => a.name== "Michael")
.Select(x => x.Id).FirstOrDefault().ToString();
首先,你需要建立YOUT應用程序和數據庫用mysql .NET連接器之間的連接。 This文章應該幫助你。
然後你應該從你的應用程序中查詢數據庫。 適合您的請求的SQL查詢將爲"SELECT id FROM table WHERE name = 'Michael'"
使用實體框架,如[LINQ](http://msdn.microsoft.com/en-us/netframework/aa904594) – zellio
SELECT id WHERE name =「Michael」。 ..? –
你可以先回去跟老師談談...... – NotMe