如何在我的网页上创建用户登录

如何在我的网页上创建用户登录

问题描述:

我想知道是否有人将视频中的这段代码转换为C#代码.

谢谢你.我正在做的项目需要它

这是视频: http://www.youtube.com/watch?v=u-FE9Ovg1to [ ^ ]

干杯J

I was wondering if somebody translate this piece of code in the video to C# code.

Thank you. I need it for a project im doing

Here is the video : http://www.youtube.com/watch?v=u-FE9Ovg1to[^]

Cheers J

由于Youtube在我们的办公室中被*,我无法打开链接.

我认为从您的问题中您可以得到答案 ^ ].
I could not able to open the link since Youtube is blocked in our office.

From your question i think you can get the answer Here[^].


好,因为您实际上发布了一些代码&尽力了,我会帮助...

OK since you actually posted some code & made an effort I''ll help...

private void SignonUser()
{ 
	DataSet commandResults = new DataSet();

	try
	{
		using (SqlConnection connection = new SqlConnection("server=CAIRNS;database=W210John;User Id=W210John;Password=fulham22"))
		{
			connection.Open();

			string commandText = "SELECT Username, Password FROM User_tbl WHERE Username = @userName AND Password = @password";
			SqlCommand cmd = new SqlCommand(commandText);
			cmd.Connection = connection;
			cmd.CommandType = CommandType.Text;

			cmd.Parameters.Add("@userName", txtUser.Text.Trim());
			cmd.Parameters.Add("@password", txtPass.Text.Trim());

			SqlDataAdapter adapter = new SqlDataAdapter();
			adapter.SelectCommand = cmd;
			adapter.Fill(commandResults);

			// Now you'll have the results back, so work with them!
			if (commandResults.Tables.Count > 0)
			{
				DataTable userDetails = commandResults.Tables[0];

				if (userDetails.Rows.Count > 0)
				{
					DataRow user = userDetails.Rows[0];

					// OK, you've got a user row...all looks good, return true or something!
				}
				else
				{
					Console.WriteLine("No matching user details");
				}
			}
			
			connection.Close();
		}
	}
	catch (SqlException exception)
	{
		// Some SQL exception handling maybe...?
	}

}