Lord
03-26-2009, 01:16 PM
Hi friends, I am newbeginner about database on ASP.NET, and trying to take datas from my database named SecData, and printing a data to a Label. I've worked on it about a week but I COULDNT DO IT!! Please help me friends
My Problem is:
1) I got a database named as "SecData",
2) and SecData has only one table named "UserData" that has two column named "Username" and "Password"
3) And finally, there is a user that has "Sean" as a Username, and "12345" as a Password.
My question is:
I need to select a user named Sean, and take his password as a string, and print into a label. I have to do it, please help friends please
My Code is:
Try.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Try.aspx.cs" Inherits="Try" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Read" />
</div>
<asp:Label ID="Label1" runat="server" Font-Names="Verdana" Text="Password"></asp:Label>
</form>
</body>
</html>
Try.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Try : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{}
protected void Button1_Click(object sender, EventArgs e)
{
SecDataDataContext sec = new SecDataDataContext();
var user = from chosen in sec.UserDatas
where chosen.Username=="Sean"
select chosen.Password;
Label1.Text = what should I write here?? }
}
My Problem is:
1) I got a database named as "SecData",
2) and SecData has only one table named "UserData" that has two column named "Username" and "Password"
3) And finally, there is a user that has "Sean" as a Username, and "12345" as a Password.
My question is:
I need to select a user named Sean, and take his password as a string, and print into a label. I have to do it, please help friends please
My Code is:
Try.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Try.aspx.cs" Inherits="Try" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Read" />
</div>
<asp:Label ID="Label1" runat="server" Font-Names="Verdana" Text="Password"></asp:Label>
</form>
</body>
</html>
Try.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Try : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{}
protected void Button1_Click(object sender, EventArgs e)
{
SecDataDataContext sec = new SecDataDataContext();
var user = from chosen in sec.UserDatas
where chosen.Username=="Sean"
select chosen.Password;
Label1.Text = what should I write here?? }
}