try to send email message in C# - asp.net

I am New in asp.net .plz help
I am trying to send email message in C# with this code
can any body tell me what is wrong with my code ??..it is building with out error but message didn't sent.
if ((!string.IsNullOrEmpty(base.Request["SECURETOKENID"]) && !string.IsNullOrEmpty(base.Request["EMAIL"])) && (base.Request["RESPMSG"] == "Approved"))
{
SqlConnection connection = new SqlConnection(Common.GetConnectionString("DBConnect"));
connection.Open();
SqlCommand command = new SqlCommand(string.Concat(new object[] { "UPDATE VIPPurchases SET PurchaseDate='", DateTime.Now, "', Status=1 WHERE PurchaseCode='", base.Request["SECURETOKENID"], "' AND Status=0" }), connection);
if (command.ExecuteNonQuery() == 1)
{
command = new SqlCommand("SELECT Ct.title, VI.VideoTitle FROM VIPView as VI INNER JOIN VIPPurchases as VP ON VI.catid = VP.VideoCode INNER JOIN categoryppv as Ct ON VP.VideoCode = Ct.catid WHERE VP.PurchaseCode='" + base.Request["SECURETOKENID"] + "' and VI.viewtype='3' AND VI.IsPublished='1'", connection);
string str = (string)command.ExecuteScalar();
command = new SqlCommand("SELECT Value FROM Settings WHERE Name='Email'", connection);
string addresses = (string)command.ExecuteScalar();
command = new SqlCommand("SELECT Fm.FilmmakerEmail, VI.VideoCode, VP.PurchaseCode FROM VIPPurchases as VP INNER JOIN VIPView as VI ON VP.VideoCode = VI.catid INNER JOIN Filmmakers as Fm ON VI.FilmmakerCode = Fm.FilmmakerCode where VP.PurchaseCode='" + base.Request["SECURETOKENID"] + "' and VI.viewtype='3' AND VI.IsPublished='1'", connection);
addresses = addresses + ", " + ((string)command.ExecuteScalar());
command = new SqlCommand("Select Value from Settings WHERE Name='SenderAddress'", connection);
string userName = (string)command.ExecuteScalar();
command = new SqlCommand("Select Value from Settings WHERE Name='SenderPassword'", connection);
string password = (string)command.ExecuteScalar();
command = new SqlCommand("Select Value from Settings WHERE Name='SMTP'", connection);
string str5 = (string)command.ExecuteScalar();
command = new SqlCommand("Select Value from Settings WHERE Name='Port'", connection);
int num = Convert.ToInt32((string)command.ExecuteScalar());
command = new SqlCommand("Select Value from Settings WHERE Name='SSL'", connection);
bool flag = command.ExecuteScalar() == "True";
SmtpClient client = new SmtpClient
{
UseDefaultCredentials = false,
Host = str5,
Port = Convert.ToInt32(num),
Credentials = new NetworkCredential(userName, password),
EnableSsl = flag
};
MailMessage message = new MailMessage
{
Subject = "platformathletics World - Inndividual Registration",
From = new MailAddress(userName)
};
message.To.Add(base.Request["EMAIL"]);
message.IsBodyHtml = true;
message.Body = "<h3>platformathletics World - (" + str + ") Purchase</h3><p>You are allowed to watch training video <b>" + str + "</b> for next 30 days (till " + DateTime.Now.AddDays(30.0).ToString("MMM dd, yyyy hh:mm tt") + "<sup style='color:red'>*</sup>) from now.</p><p>Your ticket number is <b>" + base.Request["SECURETOKENID"] + "</b>.</p><p>Put your ticket number <a href='http://" + HttpContext.Current.Request.Url.Host + "/VIPMovieList.aspx'>here</a> in return box to watch the video.</p><p><a href='http://" + HttpContext.Current.Request.Url.Host + "/login.aspx'>Login</a> or <a href='http:" + HttpContext.Current.Request.Url.Host + "/register.aspx'>register</a> to platformathletics Network to manage your My Pay Per View Purchases section.</p><br /><hr><br /><small>You could be in different time zone other than United States but your ticket will expire in exact 30 days from the time you receive this email.</small>";
client.Send(message);
message = new MailMessage
{
Subject = "platformathletics World - Inndividual Registration",
From = new MailAddress(userName)
};
message.To.Add(addresses);
message.IsBodyHtml = true;
message.Body = "<h3>platformathletics World - (" + str + ") Purchase</h3><p>Your video has been purchased. <i>" + base.Request["EMAIL"] + "</i> is allowed to watch <b>" + str + "</b> for 30 days.</p><p>Confirmation emails are also sent to " + base.Request["EMAIL"] + " and platformathletics Admin.";
client.Send(message);
this.ErrorPanel.Visible = false;
this.SuccessPanel.Visible = true;
}
Am I going on the right path??
Please help me..thanks

You should use try/catch when you actually send the message, you'll get a more descriptiive message of what's going wrong:
try
{
client.Send(message);
}
catch (Exception e)
{
//Handle exception
Console.Write(e.ToString()); //Or use another way to display the message.
}

Try this,
string mailServer;
int port;
string mailId, mailPass;
string subject;
string mailTo;
subject="something";
StringBuilder mailBody = new StringBuilder();
mailTo = "someone#gmail.com";
mailServer = "smtp.gmail.com";
mailId = "something#gmail.com";
myString.Length = 0;
myString.Append("<html><body><div>BODY CONTENT</div></body></html>");
mailPass = "xxxxxx";
port = 587;
MailMessage mail = new MailMessage(mailId, mailTo, subject, myString.ToString());
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient(mailServer, port);
System.Net.NetworkCredential nc = new System.Net.NetworkCredential(mailId, mailPass);
smtp.UseDefaultCredentials = false;
smtp.Credentials = nc;
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Send(mail);
Change mailTo, mailId, mailPass according to yours.

I'd change :
this.ErrorPanel.Visible = false;
to
this.ErrorPanel.Visible = true;
See if that gives you an error.

Related

The process cannot access the file.xlsx' because it is being used by another process. While Exporting Data from ASPX to an EXCEL file

When I try to Export I got an Exception which says that the "Process cannot access the file "Mypath\Filename.xlsx" because it is being used by another process"
The Exception is Thrown when I try to Export and it is tracked back to the Line byte[] content = File.ReadAllBytes(fileName); So I don't Understand the Problem.
Am Not Using File stream to Read data
Here are the codes I Used
protected void BtnExport_Click(object sender, EventArgs e)
{
using (MydatabaseEntities dc = new MydatabaseEntities())
{
List<EmployeeMaster> emList = dc.EmployeeMasters.ToList();
StringBuilder sb = new StringBuilder();
if (emList.Count > 0)
{
string fileName = Path.Combine(Server.MapPath("~/ImportDocument"), DateTime.Now.ToString("ddMMyyyyhhmmss") + ".xlsx");
string conString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + fileName + "; Extended Properties='Excel 12.0;HDR=yes'";
using (OleDbConnection con = new OleDbConnection(conString))
{
string strCreateTab = "Create table EmployeeData(" +
"[Employee ID] varchar(50)," +
"[Company Name] varchar(200)," +
"[Contact Name] varchar(200)," +
"[Contact Title] varchar(200)," +
"[Employee Address] varchar(200)," +
"[Postal Code] varchar(50))";
if (con.State == ConnectionState.Closed)
{
con.Open();
}
OleDbCommand cmd = new OleDbCommand(strCreateTab, con);
cmd.ExecuteNonQuery();
string StrInsert = "Insert into EmployeeData([Employee ID],[Company Name]," + "[Contact Name],[Contact Title],[Employee Address], [Postal Code]" +
")values(?,?,?,?,?,?)";
OleDbCommand cmdIns = new OleDbCommand(StrInsert, con);
cmdIns.Parameters.Add("?", OleDbType.VarChar, 50);
cmdIns.Parameters.Add("?", OleDbType.VarChar, 200);
cmdIns.Parameters.Add("?", OleDbType.VarChar, 200);
cmdIns.Parameters.Add("?", OleDbType.VarChar, 200);
cmdIns.Parameters.Add("?", OleDbType.VarChar, 200);
cmdIns.Parameters.Add("?", OleDbType.VarChar, 50);
foreach (var i in emList)
{
cmdIns.Parameters[0].Value = i.EmployeeId;
cmdIns.Parameters[1].Value = i.CompanyName;
cmdIns.Parameters[2].Value = i.ContactName;
cmdIns.Parameters[3].Value = i.ContactTitle;
cmdIns.Parameters[4].Value = i.EmployeeAddress;
cmdIns.Parameters[5].Value = i.PostalCode;
cmdIns.ExecuteNonQuery();
}
//create Downloadable File
byte[] content = File.ReadAllBytes(fileName);
HttpContext context = HttpContext.Current;
context.Response.BinaryWrite(content);
context.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
context.Response.AppendHeader("Content-Disposition", "attachment; filename=EmployeeData.xlsx");
context.Response.End();
con.Close();
}
}
}
}
}
So Help me Please
I'm really Happy that I was Able to Fix my Problem with a simple trick I tried. The Error I was Getting that The file is Already Open, was caused by the connection I didn't close before creating a downloadable file!! Here is the change I made in Bold. :-)
protected void BtnExport_Click(object sender, EventArgs e)
{
using (MydatabaseEntities dc = new MydatabaseEntities())
{
List<EmployeeMaster> emList = dc.EmployeeMasters.ToList();
StringBuilder sb = new StringBuilder();
if (emList.Count > 0)
{
string fileName = Path.Combine(Server.MapPath("~/ImportDocument"), DateTime.Now.ToString("ddMMyyyyhhmmss") + ".xlsx");
string conString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + fileName + "; Extended Properties='Excel 12.0;HDR=yes'";
using (OleDbConnection con = new OleDbConnection(conString))
{
string strCreateTab = "Create table EmployeeData(" +
"[Employee ID] varchar(50)," +
"[Company Name] varchar(200)," +
"[Contact Name] varchar(200)," +
"[Contact Title] varchar(200)," +
"[Employee Address] varchar(200)," +
"[Postal Code] varchar(50))";
if (con.State == ConnectionState.Closed)
{
con.Open();
}
OleDbCommand cmd = new OleDbCommand(strCreateTab, con);
cmd.ExecuteNonQuery();
string StrInsert = "Insert into EmployeeData([Employee ID],[Company Name]," + "[Contact Name],[Contact Title],[Employee Address], [Postal Code]" +
")values(?,?,?,?,?,?)";
OleDbCommand cmdIns = new OleDbCommand(StrInsert, con);
cmdIns.Parameters.Add("?", OleDbType.VarChar, 50);
cmdIns.Parameters.Add("?", OleDbType.VarChar, 200);
cmdIns.Parameters.Add("?", OleDbType.VarChar, 200);
cmdIns.Parameters.Add("?", OleDbType.VarChar, 200);
cmdIns.Parameters.Add("?", OleDbType.VarChar, 200);
cmdIns.Parameters.Add("?", OleDbType.VarChar, 50);
foreach (var i in emList)
{
cmdIns.Parameters[0].Value = i.EmployeeId;
cmdIns.Parameters[1].Value = i.CompanyName;
cmdIns.Parameters[2].Value = i.ContactName;
cmdIns.Parameters[3].Value = i.ContactTitle;
cmdIns.Parameters[4].Value = i.EmployeeAddress;
cmdIns.Parameters[5].Value = i.PostalCode;
cmdIns.ExecuteNonQuery();
}
//create Downloadable File
**con.Close();**
byte[] content = File.ReadAllBytes(fileName);
HttpContext context = HttpContext.Current;
context.Response.BinaryWrite(content);
context.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
context.Response.AppendHeader("Content-Disposition", "attachment; filename=EmployeeData.xlsx");
context.Response.End();
}
}
}
}
}

What is ZRangeValid means

This code is to read an excel file, what is ZRangeValid means and what is rs.fields(0).value referring to? Please explain my two questions
var strConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + strXLPath + ";Extended Properties=\"Excel 12.0;HDR=YES;\";";
var conn = new ActiveXObject("ADODB.Connection");
conn.open(strConnString, "", "");
var rs = new ActiveXObject("ADODB.Recordset");
var rsrowCount = new ActiveXObject("ADODB.Recordset");
rs = conn.execute("select * from ZRangeValid");
if (rs.fields(0).value != 'YES') {
alert(strXLPath + " requested numbers spreadsheet is not valid.\nPlease validate the spreadsheet data and retry.")
rs = null;
rsSheet = null;
conn.close();
conn = null;
return false
}

Label does not show up in asp.net

I have a label in asp.net page and change its text in certain situations. Here is the code:
<asp:Label ID="errorMessage" runat="server" Text="Label" Visible="False"></asp:Label>
errorMessage.Text = MyGlobals.student.registerCourse(c, ref addList, course).ToString();
errorMessage.ForeColor = System.Drawing.Color.Red;
errorMessage.Visible = true;
When i debugged, i saw that MyGlobals.student.registerCourse(c, ref addList, course).ToString() method returns my error message well. Then i set the label visible, but when page loads i cannot see the label. Also, while debugging i saw that "textsetbyaddparsedsubobject" property of the label is false. Can that be the problem? Why is not the label being showed in my page? Can anyone help?
Thanks.
Edit: Here is the full code:
protected void bSubmitChanges_Click1(object sender, EventArgs e)
{
Userfunctions function = new Userfunctions();
List<string> dropList = new List<string>();
List<string> addList = new List<string>();
SqlConnection con = new SqlConnection();
con.ConnectionString = Userfunctions.GetConnectionString();
SqlCommand cmd;
con.Open();
string ID = MyGlobals.currentID;
try
{
for (int i = 1; i <= 6; i++)
{
string course;
if ((course = boxCRN(i)) != "")
{
cmd = new SqlCommand("select count (*) from CourseTable where CRN=#course", con);
cmd.Parameters.AddWithValue("#course", course);
int result = Convert.ToInt32(cmd.ExecuteScalar());
if (result > 0)
{
cmd = new SqlCommand("select * from CourseTable where CRN=#course", con);
cmd.Parameters.AddWithValue("#course", course);
cmd.ExecuteScalar();
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
foreach (DataRow dr in dt.Rows)
{
string query = "SELECT * FROM CourseTable WHERE CourseCode='" + dr["CourseCode"] + "' AND CourseNumber='" + dr["CourseNumber"] + "' AND Term='" + dr["Term"] + "'";
cmd = new SqlCommand(query, con);
SqlDataAdapter da2 = new SqlDataAdapter(cmd);
DataTable dt2 = new DataTable();
da2.Fill(dt2);
DataRow dr2 = dt2.Rows[0];
cmd = new SqlCommand("select * from PrereqTable where CourseCode='" + dr["CourseCode"] + "' AND CourseNumber='" + dr["CourseNumber"] + "' AND Term='" + dr["Term"] + "'", con);
da2 = new SqlDataAdapter(cmd);
dt2 = new DataTable();
da2.Fill(dt2);
List<string> pre = new List<string>();
foreach (DataRow dr5 in dt2.Rows)
{
pre.Add(Convert.ToString(dr5["pCourseCode"]) + Convert.ToString(dr5["pCourseNumber"]));
}
Course c = new Course(dr2["InstructorID"].ToString(), dr2["CourseCode"].ToString(), dr2["CourseNumber"].ToString(), dr2["CourseName"].ToString(), dr2["Term"].ToString(), dr2["CRN"].ToString(), dr2["Level"].ToString(), dr2["Credit"].ToString(), dr2["Description"].ToString(), dr2["Capacity"].ToString());
c.addPrereq(pre);
string message = MyGlobals.student.registerCourse(c, ref addList, course).ToString();
errorMessage.Text = message;
errorMessage.ForeColor = System.Drawing.Color.Red;
errorMessage.Visible = true;
Label1.Visible = true;
Label1.Text = "asdasdasd";
}
}
}
}
}
catch (Exception) { }
for (int i = 0; i < showCourses.Rows.Count; i++)
{
string a = ((DropDownList)showCourses.Rows[i].FindControl("actionmenu")).SelectedValue;
if (((DropDownList)showCourses.Rows[i].FindControl("actionmenu")).SelectedValue == "1")
{
string courseCode = showCourses.Rows[i].Cells[1].Text, courseNumber = showCourses.Rows[i].Cells[2].Text;
SqlCommand com = new SqlCommand("select * from CourseTable where CourseCode=#courseCode and CourseNumber=#courseNumber", con);
com.Parameters.AddWithValue("courseCode", courseCode);
com.Parameters.AddWithValue("courseNumber", courseNumber);
try
{
SqlDataAdapter da2 = new SqlDataAdapter(com);
DataTable dt2 = new DataTable();
da2.Fill(dt2);
DataRow dr2 = dt2.Rows[0];
Course c = new Course(dr2["InstructorID"].ToString(), dr2["CourseCode"].ToString(), dr2["CourseNumber"].ToString(), dr2["CourseName"].ToString(), dr2["Term"].ToString(), dr2["CRN"].ToString(), dr2["Level"].ToString(), dr2["Credit"].ToString(), dr2["Description"].ToString(), dr2["Capacity"].ToString());
Register reg = new Register(c, MyGlobals.student);
MyGlobals.student.dropCourse(reg);
dropList.Add(showCourses.Rows[i].Cells[1].Text + showCourses.Rows[i].Cells[2].Text);
}
catch (Exception) { }
}
}
foreach (string course in dropList)
{
for (int i = 0; i < MyGlobals.student.getRegistered().Count; i++ )
{
if (MyGlobals.student.getRegistered()[i].getCourse().getCode().ToString() + MyGlobals.student.getRegistered()[i].getCourse().getNumber().ToString() == course)
MyGlobals.student.dropCourse(MyGlobals.student.getRegistered()[i]);
}
cmd = new SqlCommand("delete from RegisterTable where StudentID='" + MyGlobals.currentID + "' and CourseCode='" + course.Substring(0, course.Length - 3) + "' and CourseNumber='" + course.Substring(course.Length - 3, 3) + "'", con);
cmd.ExecuteNonQuery();
}
try
{
foreach (string courses in addList)
{
string courseCode = "";
string courseNumber = "";
string term = MyGlobals.currentTerm + " " + MyGlobals.currentYear;
string q = ("select CourseCode from CourseTable where CRN=#courses");
string grade = "";
SqlCommand command = new SqlCommand(q, con);
command.Parameters.AddWithValue("#courses", courses);
courseCode = Convert.ToString(command.ExecuteScalar());
q = ("select CourseNumber from CourseTable where CRN=#courses");
command = new SqlCommand(q, con);
command.Parameters.AddWithValue("#courses", courses);
courseNumber = Convert.ToString(command.ExecuteScalar());
cmd = new SqlCommand("insert into RegisterTable (CourseCode,CourseNumber,Term,StudentID,Grade) values(#courseCode,#courseNumber,#term, #ID,'U')", con);
cmd.Parameters.AddWithValue("#courseCode", courseCode);
cmd.Parameters.AddWithValue("#courseNumber", courseNumber);
cmd.Parameters.AddWithValue("#term", term);
cmd.Parameters.AddWithValue("#ID", ID);
cmd.Parameters.AddWithValue("#grade", grade);
cmd.ExecuteNonQuery();
}
}
catch (Exception) { }
con.Close();
Response.Redirect("AddDropClasses.aspx");
}
}
And the registerCourse function:
public string registerCourse(Course course, ref List <string> addList, string crn) {
bool registered = true;
string message ="";
foreach (string s in course.getTime())
{
Userfunctions f = new Userfunctions();
foreach (Register r in this.register) {
if (r.getCourse().getTerm() == MyGlobals.currentTerm.ToString() + " " + MyGlobals.currentYear.ToString() && !f.TimeCheck(s, r.getCourse().getTime()))
{
registered = false;
message = "Time conflict";
}
}
}
if (registered) {
SqlConnection con = new SqlConnection();
con.ConnectionString = Userfunctions.GetConnectionString();
con.Open();
string id = MyGlobals.currentID;
SqlCommand cmd = new SqlCommand("SELECT count (*) from RegisterTable where CourseCode ='" + course.getCode() +"' and CourseNumber='" + course.getNumber() + "' and Term='" + course.getTerm()+"'" , con);
cmd.Parameters.AddWithValue("#id", id);
int active = Convert.ToInt32(cmd.ExecuteScalar());
if (active >= Convert.ToInt32(course.getCapacity())){
registered = false;
message = "Not enough capacity";
}
if (registered) {
foreach (string s in course.getPrerequisites()) {
if (!hasPassedCourse(s)) {
registered = false;
message = "Prerequisite error";
}
}
}
}
if (registered)
{
Register reg = new Register(course, MyGlobals.student);
MyGlobals.student.addToSchedule(reg);
addList.Add(crn);
}
return message;
}
Remove below line
Response.Redirect("AddDropClasses.aspx");
it will load your page again as new page
When you have Visible="false" set on the control then the control properties may not been instatiated fully.
I would try hiding the control using, errorMessage.Visible=false in the code-behind in your Page_Load instead.

There is no row at position 0 error at asp.net

I was writing a web based program and this is my authentication page. It was working fine but suddenly it started to give that error.
Here is my code:
else if (LoginAs.SelectedValue == "Student")
{
string tableName = "StudentTable";
String name = "", surname = "", email = "";
string query = "Select level from " + tableName + " where ID='" + idBox.Text + "'";
SqlCommand cmd = new SqlCommand(query, con);
string level = Convert.ToString(cmd.ExecuteScalar());
CreateUser(con, tableName, ref name, ref surname, ref email);
query = "Select program from " + tableName + " where ID='" + idBox.Text + "'";
cmd = new SqlCommand(query, con);
string program = Convert.ToString(cmd.ExecuteScalar());
MyGlobals.student = new Student(Convert.ToInt32(idBox.Text), "Active", email, name, surname, password, level, program);
MyGlobals.currentID = idBox.Text;
query = "Select * from RegisterTable where StudentID='" + idBox.Text + "'";
cmd = new SqlCommand(query, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
foreach (DataRow dr in dt.Rows)
{
query = "SELECT * FROM CourseTable WHERE CourseCode='" + dr["CourseCode"] + "' AND CourseNumber='" + dr["CourseNumber"] + "' AND Term='" + dr["Term"] + "'";
cmd = new SqlCommand(query, con);
SqlDataAdapter da2 = new SqlDataAdapter(cmd);
DataTable dt2 = new DataTable();
da2.Fill(dt2);
DataRow dr2 = dt2.Rows[0]; //ERROR COMES AT HERE
Course course = new Course(dr2["InstructorName"].ToString(), dr2["CourseCode"].ToString(), dr2["CourseNumber"].ToString(), dr2["CourseName"].ToString(), dr2["Term"].ToString(), dr2["CRN"].ToString(), dr2["Level"].ToString(), dr2["Credit"].ToString(), dr2["Description"].ToString(), dr2["Capacity"].ToString());
Register reg = new Register(course, MyGlobals.student);
MyGlobals.student.addToSchedule(reg);
}
int num = (int)Application["OnlineUsers"];
Response.Redirect("Student.aspx");
}
Can anyone help me with this? Thanks in advance.
You don't specify where the exception is thrown but a very common reason for this (my opinion) is that your query doesn't return any results (or rows).

Strange! MySQL update not working without error

The below is my code to create account in my project. The code is working perfect till Response.Write(iduser) but the UPDATE command is not working. No error found using exception but MySQL's record is not updated.
try
{
string pet1 = "admin#testlite.php";
string MyConString = "DRIVER={MySQL ODBC 3.51 Driver};" + "SERVER=localhost;" + "DATABASE=newtest;" + "UID=root;" + "PASSWORD=**********;" + "OPTION=3";
OdbcConnection MyConnection = new OdbcConnection(MyConString);
OdbcCommand cmd = new OdbcCommand("Select id_user from awm_accounts where email=?", MyConnection);
cmd.Parameters.Add("#val1", OdbcType.VarChar, 255).Value = pet1;
MyConnection.Open();
OdbcDataReader dr = cmd.ExecuteReader();
if (dr.HasRows == false)
{
throw new Exception();
}
if (dr.Read())
{
int iduser = Convert.ToInt32(dr[0].ToString());
Account acct = new Account();
acct.Email = username.Text + domain.Text;
acct.MailIncomingLogin = username.Text + domain.Text;
acct.MailIncomingHost = "imap." + DropDownList1.SelectedValue;
acct.MailIncomingPassword = password.Text;
acct.MailIncomingPort = 993;
acct.MailOutgoingHost = "smtp." + DropDownList1.SelectedValue;
acct.MailOutgoingPort = 465;
acct.MailIncomingProtocol = IncomingMailProtocol.Imap4;
acct.MailOutgoingAuthentication = true;
acct.DefaultAccount = false;
acct.IDUser = 1;
integr.CreateUserFromAccount(acct);
Response.Write(iduser);
if (!IsPostBack)
{
cmd = new OdbcCommand("UPDATE awm_accounts SET id_user=? WHERE email=? ", MyConnection);
cmd.Parameters.Add("#tb_nickname", OdbcType.Int, 11).Value = iduser;
cmd.Parameters.Add("#tb_fullname", OdbcType.VarChar, 255).Value = username.Text + domain.Text;
cmd.ExecuteNonQuery();
}
}
MyConnection.Close();
}
catch (Exception exp)
{
Response.Write(exp);
}
I'm not sure about the Response.Write part but I am sure that you create a SQLCommand but never actually execute it.
Did you forget to put a cmd.executeNonScalar() in there?

Resources