c#

database connection in c#

Page 1 of 1

4 Replies - 2196 Views - Last Post: 21 April 2010 - 06:06 AM Rate Topic: -----

#1 mobashir   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 21-April 10

c#

Posted 21 April 2010 - 05:49 AM

Help me
i hav designed a registration form and login form in asp.net.i want to store the data entered by the user in registration page to mydatabase in c#.i have done coding in this way but it didnot work
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
public partial class login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        {
            SqlConnection con = new SqlConnection();
            con.ConnectionString = ConfigurationSettings.AppSettings["strConnectionString"];
            con.Open();
            Response.Write("Connection is Open");
        }
    }
    protected void btnClick_Click(object sender, EventArgs e)
    {
        if(txtUserName.Text=="khan" && txtPassword.Text=="khan")
        {
            Response.Redirect("registration.aspx");
        }
            else
        {
            lblError.Text = "Please enter correct username and password";
        }
   }
@[member='sarmanu']

Is This A Good Question/Topic? 0
  • +

Replies To: c#

#2 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6246
  • View blog
  • Posts: 24,014
  • Joined: 23-August 08

Re: c#

Posted 21 April 2010 - 05:53 AM

Moved to ASP.NET, and please define "did not work"
Was This Post Helpful? 0
  • +
  • -

#3 Sergio Tapia   User is offline

  • D.I.C Lover
  • member icon

Reputation: 1258
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: c#

Posted 21 April 2010 - 05:58 AM

Can you show us the code for registration.aspx; I'm guess that is where you actually save the information.
Was This Post Helpful? 0
  • +
  • -

#4 mobashir   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 21-April 10

Re: c#

Posted 21 April 2010 - 06:03 AM

thnx for ur reply registration.aspx coe is here.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="registration.aspx.cs" Inherits="registration" %>

<!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 style="background-color: Silver">
    <form id="form1" runat="server">
    <div align="center">
        <table>
            <tr>
                <td>
                    First Name
                </td>
                <td>
                    <asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtFirstName"
                        ErrorMessage="First Name Required"></asp:RequiredFieldValidator>
                </td>
                <tr>
                    <td>
                        Last Name
                    </td>
                    <td>
                        <asp:TextBox ID="txtLastName" runat="server"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtLastName"
                            ErrorMessage="Last Name Require"></asp:RequiredFieldValidator>
                    </td>
                </tr>
            </tr>
            <tr>
                <td>
                    User Name
                </td>
                <td>
                    <asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtUserName"
                        ErrorMessage="User Name Required"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td>
                    Password
                </td>
                <td>
                    <asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="txtPassword"
                        ErrorMessage="Password Required"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td>
                    Confirm Password
                </td>
                <td>
                    <asp:TextBox ID="txtConfirmPassword" runat="server" TextMode="Password"></asp:TextBox>
                </td>
            </tr>
            <br />
            <tr>
                <td>
                    <asp:Button ID="btnSave" runat="server" Text="Save" onclick="btnSave_Click" />
                </td>
                <td>
                    <asp:LinkButton ID="lnkGoBack" runat="server" Text="GoBack" onclick="lnkGoBack_Click"></asp:LinkButton>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>

Was This Post Helpful? 0
  • +
  • -

#5 Sergio Tapia   User is offline

  • D.I.C Lover
  • member icon

Reputation: 1258
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: c#

Posted 21 April 2010 - 06:06 AM

I meant the code behind file; show me this method: btnSave_Click

This post has been edited by stapia.gutierrez: 21 April 2010 - 06:06 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1