Tech Support Forum banner
Status
Not open for further replies.
1 - 1 of 1 Posts

·
Registered
Joined
·
16 Posts
Discussion Starter · #1 · (Edited)
Well, I have run into a problem where I load this page named DetailsEdit, and load my users details from an SQL database and display them in text boxes.

When the users look at this page, it is to allow them to edit and change their details.

When the page loads, they can see the labels and the correct text boxes with the data pulled from the MemberDetails table.

Then i have an event when the Confirm button is pressed which will update all the same fields in the MemberDetails table with the NEW contents of each text box.

Now after they edit any text box (which I have reduced to only testing 'Title') and then click on the confirm button, the text box contents havent changed in the codes pov.

I just dont understand why it wont read what has been newly entered into the text box, since i have gotten the same kind of query to work on another page.

Any ideas would be much appreciated.



Heres my code, first time ive really done this so probably way more efficient ways of writing the SQL code.


using
System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
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.Xml.Linq;
using System.Data.SqlClient;
namespace Projectnew
{
publicpartialclassDetailsEdit : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
int Key = Convert.ToInt16(Cache.Get("key"));
SqlConnection conn = null;
conn = newSqlConnection("Data Source=HOME-PC\\SQLEXPRESS;Initial Catalog=Members;Integrated Security=True");

string strSQLCommand1 = "SELECT Title FROM MemberDetails WHERE (ID = @Key)";
string strSQLCommand2 = "SELECT Forename FROM MemberDetails WHERE (ID = @Key)";
string strSQLCommand3 = "SELECT Surname FROM MemberDetails WHERE (ID = @Key)";
string strSQLCommand4 = "SELECT Street FROM MemberDetails WHERE (ID = @Key)";
string strSQLCommand5 = "SELECT Town FROM MemberDetails WHERE (ID = @Key)";
string strSQLCommand6 = "SELECT Postcode FROM MemberDetails WHERE (ID = @Key)";
SqlCommand command1 = newSqlCommand(strSQLCommand1, conn);
SqlCommand command2 = newSqlCommand(strSQLCommand2, conn);
SqlCommand command3 = newSqlCommand(strSQLCommand3, conn);
SqlCommand command4 = newSqlCommand(strSQLCommand4, conn);
SqlCommand command5 = newSqlCommand(strSQLCommand5, conn);
SqlCommand command6 = newSqlCommand(strSQLCommand6, conn);

SqlParameter key1Param = command1.Parameters.Add("@Key", SqlDbType.VarChar);
SqlParameter key2Param = command2.Parameters.Add("@Key", SqlDbType.VarChar);
SqlParameter key3Param = command3.Parameters.Add("@Key", SqlDbType.VarChar);
SqlParameter key4Param = command4.Parameters.Add("@Key", SqlDbType.VarChar);
SqlParameter key5Param = command5.Parameters.Add("@Key", SqlDbType.VarChar);
SqlParameter key6Param = command6.Parameters.Add("@Key", SqlDbType.VarChar);
key1Param.Value = Key;
key2Param.Value = Key;
key3Param.Value = Key;
key4Param.Value = Key;
key5Param.Value = Key;
key6Param.Value = Key;

conn.Open();

TitleTextBox.Text = (string)command1.ExecuteScalar();
ForenameTextBox.Text = (string)command2.ExecuteScalar();
SurnameTextBox.Text = (string)command3.ExecuteScalar();
StreetTextBox.Text = (string)command4.ExecuteScalar();
TownTextBox.Text = (string)command5.ExecuteScalar();
PostcodeTextBox.Text = (string)command6.ExecuteScalar();
conn.Close();
}
protectedvoid ConfBut_Click(object sender, EventArgs e)
{
int Key = Convert.ToInt16(Cache.Get("key"));
SqlConnection conn = null;
conn = newSqlConnection("Data Source=HOME-PC\\SQLEXPRESS;Initial Catalog=Members;Integrated Security=True");
string strSQLCommand1 = "UPDATE MemberDetails SET Title = @Title WHERE (ID = @Key)";
SqlCommand command1 = newSqlCommand(strSQLCommand1, conn);

SqlParameter keyParam = command1.Parameters.Add("@Key", SqlDbType.VarChar);
SqlParameter titleParam = command1.Parameters.Add("@Title", SqlDbType.VarChar);

//SqlParameter ForenameParam = dataCommand.Parameters.Add("@Forename", SqlDbType.VarChar);
//SqlParameter SurnameParam = dataCommand.Parameters.Add("@Surname", SqlDbType.VarChar);
//SqlParameter StreetParam = dataCommand.Parameters.Add("@Street", SqlDbType.VarChar);
//SqlParameter TownParam = dataCommand.Parameters.Add("@Town", SqlDbType.VarChar);
//SqlParameter PostcodeParam = dataCommand.Parameters.Add("@Postcode", SqlDbType.VarChar);
keyParam.Value = Key;
titleParam.Value = TitleTextBox.Text;
//ForenameParam.Value = ForenameTextBox.Text;
//SurnameParam.Value = SurnameTextBox.Text;
//StreetParam.Value = StreetTextBox.Text;
//TownParam.Value = TownTextBox.Text;
//PostcodeParam.Value = PostcodeTextBox.Text;
conn.Open();
command1.ExecuteNonQuery();
conn.Close();
Response.Redirect(http://localhost:56508/Profile.aspx);
}
}
}
 
1 - 1 of 1 Posts
Status
Not open for further replies.
Top