Hi!
I am developing a web base project(Online Virtual Drive). While creating a “Signup Page” I have some problem In my code, where I want to “save” and “retrieve” user information in database. But I cannot be understanding the problem. Please solve the problem if any body can do do. I will be thankful to you.
ASP CODE:
<tr>
<td colspan="5" style="height: 500px; text-align: left; vertical-align: top;">
<br />
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="Name"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" OnTextChanged="TextBox1_TextChanged" Width="343px"></asp:TextBox><br />
<br />
<asp:Label ID="Label2" runat="server" Text="Password"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server" OnTextChanged="TextBox2_TextChanged" Width="343px"></asp:TextBox><br />
<br />
<asp:Label ID="Label3" runat="server" Text="Father Name"></asp:Label>
<asp:TextBox ID="TextBox3" runat="server" OnTextChanged="TextBox3_TextChanged" Width="343px"></asp:TextBox><br />
<br />
<asp:Label ID="Label4" runat="server" Text="EMail"></asp:Label>
<asp:TextBox ID="TextBox4" runat="server"
OnTextChanged="TextBox4_TextChanged" Width="343px"></asp:TextBox><br />
<br />
<asp:Label ID="Label5" runat="server" Text="Postal Code"></asp:Label> <asp:TextBox ID="TextBox5" runat="server" OnTextChanged="TextBox5_TextChanged" Width="343px"></asp:TextBox><br />
<br />
<asp:Label ID="Label6" runat="server" Text="City/Province"></asp:Label>
<asp:TextBox ID="TextBox6" runat="server" OnTextChanged="TextBox6_TextChanged" Width="343px"></asp:TextBox><br />
<br />
<asp:Label ID="Label7" runat="server" Text="Country"></asp:Label>
<asp:TextBox ID="TextBox7" runat="server" OnTextChanged="TextBox7_TextChanged" Width="343px"></asp:TextBox><br />
<br />
<br />
<asp:Button ID="Submit1" runat="server" OnClick="Submit1_Click" Text="Submit" />
<asp:Button ID="Reset1" runat="server" OnClick="Reset1_Click" Text="Reset" /></td>
C# Code:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class signup : System.Web.UI.Page
{
SqlConnection criteriaConnection;
protected void Page_Load(object sender, EventArgs e)
{
criteriaConnection = new SqlConnection("Data Source=Home;Initial Catalog=OVD;Integrated Security=True");
}
public string storeInformation(string generatedUserId)
{
string recordToBeEntered = UserID.text.ToString();
SqlCommand verifyStatus = new SqlCommand("SELECT * FROM Registration WHERE UserID ='"+recordToBeEntered+"'", criteriaConnection);
SqlDataAdapter verifyAdapter = new SqlDataAdapter(verifyStatus);
DataTable verifyTable = new DataTable();
verifyAdapter.Fill(verifyTable);
int noOfRecords = verifyTable.Rows.Count;
if (noOfRecords < 1) // No duplicate record found, there will be no duplication.
{
SqlCommand insertInRegistrationTable = new SqlCommand("INSERT INTO Registration (UserID, Name, Password, FName, EMail, PCode, City_Province, Country) VALUES ('" + generatedProjectId.ToString() + "','" + Name.Text.ToString() + "','" + Password.Text.ToString() + "','" + FName.Text.ToString() + "','" + EMail.Text.ToString() + "','" + PCode.Text.ToString() + "','" + City_Province.Text.ToString() + "','" + Country.Text.ToString() + "')", criteriaConnection);
insertInProjectIDTable.ExecuteNonQuery();
MessageBox.Show("Data is Successfully Entered!");
}
else // ID already exists ....
{
MessageBox.Show("Data of the ID is Already Entered");
}
return "true";
}
protected void cmdpost_Click6(object sender, EventArgs e)
{
if (Page.IsValid)
{
Response.Redirect("Home.aspx", true);
}
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
}
protected void TextBox2_TextChanged(object sender, EventArgs e)
{
}
protected void TextBox3_TextChanged(object sender, EventArgs e)
{
}
protected void TextBox4_TextChanged(object sender, EventArgs e)
{
}
protected void TextBox5_TextChanged(object sender, EventArgs e)
{
}
protected void TextBox6_TextChanged(object sender, EventArgs e)
{
}
protected void TextBox7_TextChanged(object sender, EventArgs e)
{
}
protected void Submit1_Click(object sender, EventArgs e)
{
criteriaConnection.Open();
SqlCommand criteriaInsertCommand = new SqlCommand("Insert Into Registration (UserID, Name, Password, FName, EMail, PCode, City_Province, Country) Values ('" + generatedProjectId.ToString() + "','" + Name.Text.ToString() + "','" + Password.Text.ToString() + "','" + FName.Text.ToString() + "','" + EMail.Text.ToString() + "','" + PCode.Text.ToString() + "','" + City_Province.Text.ToString() + "','" + Country.Text.ToString() + "')", criteriaConnection);
criteriaInsertCommand.ExecuteNonQuery();
criteriaConnection.Close();
}
protected void Reset1_Click(object sender, EventArgs e)
{
}
SQL 2005 Table: