Oppure

Loading
30/08/17 16:08
La mail non va riscritta? Che vuoi dire? Sai cosa vuol dire la parte WHERE nella frase SQL?

Ma se hai tutte queste carenze di base, perché non studi prima e solo dopo tempo e pazienza cominci a scrivere codice?

Non è possibile spiegarti tutti gli errori che fai, non si può fare un corso di base di ADO.NET o SQL in un thread in un forum !
31/08/17 13:40
fosforo
Hai ragione.
Forse l'argomento, oltre a non essere spiegato bene, è troppo complesso da chiedere in un forum.

Cmq ti ho dato retta.
Ho studiato e risolto.

Se può essere utile a altri principianti come me posto il codice.

aaa
31/08/17 16:44
lumo
Ciao fosforo, sarebbe molto utile se condividessi la risoluzione.
aaa
31/08/17 16:59
Postato originariamente da fosforo:

Hai ragione.
Forse l'argomento, oltre a non essere spiegato bene, è troppo complesso da chiedere in un forum.

Cmq ti ho dato retta.
Ho studiato e risolto.

Se può essere utile a altri principianti come me posto il codice.



Ah, quindi non avevi idea di come usare SQL e ADO.NET, ci hai pensato mezza giornata, studiato tutto qualche ora e hai risolto, codice a posto, tutto ok?

Ma perché non l'hai fatto prima di postare?

Io penso che tu non abbia risolto nulla in mezza giornata perché non sono argomenti che si esauriscono così velocemente, anzi, si continuano a studiare per anni. Comunque, affari tuoi...
31/08/17 17:30
tuttodiMC
Finora ho capito solo che prendeva dati da un DB, li metteva nella textbox, e dopo dalla textbox lo rinviava al db, uguale a prima... forse è per questo che non notava cambiamenti :rofl::rotfl:
aaa
04/09/17 12:50
fosforo
Non pensavo di alzare un polverone cosi.
Cmq visto che un forum esiste per aiutare chi è in difficoltà
ecco quello che ho fatto.
Non so dire se è perfetto, sicuro sarà ottimizzabile.


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;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;


public partial class UserPage : System.Web.UI.Page
{
string Rename, Resurname, Reemail, Remobile, Restate, Recountry, Recity, Restreet, Rehousenumber,
Rezipcode, Rejob, Reinterest, Rehobby, Redob, Regender = "";

SqlConnection conn = null;
SqlCommand com = null;

string str;

protected void Page_Load(object sender, EventArgs e)
{

if (Page.IsPostBack) //Ricarico i dati dalle TextBox con i dati nuovi
{
Rename = txtName.Text;
Resurname = txtSurname.Text;
Reemail = txtEmail.Text;
Remobile = txtMobile.Text;
Restate = txtState.Text;
Recountry = txtCountry.Text;
Recity = txtCity.Text;
Restreet = txtStreet.Text;
Rehousenumber = txtHousenumber.Text;
Rezipcode = txtZipcode.Text;
Rejob = txtJob.Text;
Reinterest = txtInterest.Text;
Rehobby = txtHobby.Text;
Regender = (DropGender.Text);

Redob = ((DropDay.Text + "-" + DropMonth.Text + "-" + DropYear.Text)); // Keep data of bird from DropList

WriteDB(); // chiama WriteDB Scrive sul DB -------------------
}

if (Session["Session"] != null)
{
tblLogged.Visible = true; // Tabella tblLogged
str = Cache["B"].ToString(); // Name from cache
lblNameLogged.Text = str;

str = Cache["A"].ToString(); // Email from cache

conn = new SqlConnection(ConfigurationManager.ConnectionStrings["string"].ConnectionString);
conn.Open();

string checkMail = "select count(*) from Users where email='" + str + "'";

com = new SqlCommand(checkMail, conn);
int temp = Convert.ToInt32(com.ExecuteScalar().ToString());

if (temp == 1)
{

str = "select * from Users where email='" + Cache["A"] + "'";
com = new SqlCommand(str, conn);

SqlDataReader reader = com.ExecuteReader();

if (reader.Read())
{
txtName.Text = reader["name"].ToString();
txtSurname.Text = reader["surname"].ToString();
txtEmail.Text = reader["email"].ToString().Replace(" ", "";);
txtMobile.Text = reader["mobile"].ToString();
txtState.Text = reader["state"].ToString();
txtCountry.Text = reader["country"].ToString();
txtCity.Text = reader["city"].ToString();
txtStreet.Text = reader["street"].ToString();
txtHousenumber.Text = reader["housenumber"].ToString();
txtZipcode.Text = reader["zipcode"].ToString();
txtJob.Text = reader["job"].ToString();
txtInterest.Text = reader["interest"].ToString();
txtHobby.Text = reader["hobby"].ToString();

string cc = reader["dob"].ToString(); // read dob from DB
DropYear.Items[0].Text = cc.Substring(cc.LastIndexOf("-";) + 1, 4); //dropbox year
DropMonth.Items[0].Text = cc.Substring(cc.IndexOf("-";) + 1, (cc.LastIndexOf("-";) - 3)); //dropbox month
DropDay.Items[0].Text = cc.Substring(0, cc.IndexOf("-";)); //dropbox day

DropGender.Items[0].Text = reader["gender"].ToString().Replace(" ", "";);

Image1.ImageUrl = "thumbnail//" + reader["thumbnail"].ToString(); //Thumbnail from DB
}
conn.Close();
}
else
{
string script = "alert('LOGIN FAILED!');";
System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "LOGIN FAILED...", script, true);
tblLogged.Visible = false;
conn.Close();
}
}

else
{
ScriptManager.RegisterStartupScript(this, GetType(), "Success", "alert('NOT LOGGED IN...');location.href='/LoginPage.aspx'", true);
}
}

protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
WriteDB();

}

protected void WriteDB()
{

if (Session["Session"] != null)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["connection"].ConnectionString);
conn.Open();
string editQuery = "UPDATE Users SET name=@name, surname=@surname,email=@email,mobile=@mobile,city=@city,street=@street,housenumber=@housenumber,zipcode=@zipcode,country=@country,state=@state,job=@job,interest=@interest,hobby=@hobby,dob=@dob,gender=@gender,thumbnail=@thumbnail WHERE email ='" + Cache["A"].ToString() + "'";
SqlCommand com = new SqlCommand(editQuery, conn);

try
{
com.Parameters.AddWithValue("@name", Rename);
com.Parameters.AddWithValue("@surname", Resurname);
com.Parameters.AddWithValue("@email", Reemail);
com.Parameters.AddWithValue("@mobile", Remobile);
com.Parameters.AddWithValue("@city", Recity);
com.Parameters.AddWithValue("@street", Restreet);
com.Parameters.AddWithValue("@housenumber", Rehousenumber);
com.Parameters.AddWithValue("@zipcode", Rezipcode);
com.Parameters.AddWithValue("@country", Recountry);
com.Parameters.AddWithValue("@state", Restate);
com.Parameters.AddWithValue("@job", Rejob);
com.Parameters.AddWithValue("@interest", Reinterest);
com.Parameters.AddWithValue("@hobby", Rehobby);
com.Parameters.AddWithValue("@dob", Redob);
com.Parameters.AddWithValue("@gender", Regender);
com.Parameters.AddWithValue("@thumbnail", "xxxx";);

com.ExecuteNonQuery();

//string script = "alert('Registration is successful...');";
//System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Registration is successful...", script, true);

conn.Close();
conn.Dispose();
}

catch (Exception ex)
{
string Script = "alert('alert...');";
System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alert...", Script, true);
Label1.Text = ex.ToString();

}

}

else
{
string script = "alert('zzzzzzzzzzz...');";
System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "aaal...", script, true);
}
}
}
[\code]





Scusate ancora per il disturbo.
Ultima modifica effettuata da fosforo 08/09/17 7:04
aaa
04/09/17 13:38
lumo
Riusciresti a inserirlo con il tag code?
aaa
05/09/17 16:04
fosforo
Purtroppo non so cos'è il tag code.
aaa