[ASP.net#VB]ไม่ทราบ ForgetPassword ต้องเขียนโคดไงอ่ะครับ
ใช้ DataTable ดีกว่าน่ะครับ เมื่อได้ค่าก็ให้ใช้คำสั่ง
Code (VB.NET)
IF dt.Rows.Count > 0 Then
Me.lblLabel2.Text = dt.Rows(0)("Username")
End IF
Go to : ASP.NET System.Data.SqlClient - DataTable()
Date :
2010-10-02 05:44:28
By :
webmaster
Code (VB.NET)
Protected Sub btnsent_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnsent.Click
Dim dtAdapter As SqlDataAdapter
Dim dt As New DataTable
strSQL = "SELECT [Username] FROM [Member] WHERE [UserName]=@UserName"
objCmd = New SqlCommand(strSQL, objConn)
objCmd.Parameters.AddWithValue("@UserName", Me.txtrepassword.Text)
dtAdapter = New SqlDataAdapter(strSQL, objConn)
dtAdapter.Fill(dt)
If dt.Rows.Count > 0 Then
Me.Label2.Text = dt.Rows(0)("Username").ToString()
End If
End Sub
แต่ตกลงให้มันโชว์ user หรือ password
Date :
2010-10-02 18:13:58
By :
tungman
ตอนนี้ ผมทำ
ให้กรอก Username กับ Email แล้ว โชว์ Password ได้แล้วครับ
ไม่ทราบ ท่า จะให้ส่ง Password ไปทาง Email ต้อง ทำยังไงอ่ะครับ
ขอบคุณครับ
Code VB ที่ใช้
Code (VB.NET)
Dim strConnection As String = "Data Source=DELL_BLUE-PC;Initial Catalog=Research;Integrated Security=True"
Dim Connection As New SqlConnection(strConnection)
Dim strCommand As String = "Select [UserID], [UserPassword] From [Member] Where [UserName]=@UserName And [Email]=@Email"
Dim Command As New SqlCommand(strCommand, Connection)
Command.Parameters.AddWithValue("@UserName", txtrepassword.Text)
Command.Parameters.AddWithValue("@Email", txtrepassword2.Text)
Dim Dt As New DataTable()
Dim adapter As New SqlDataAdapter(Command)
adapter.Fill(Dt)
Dim UserID As Integer = 0
If Dt.Rows.Count > 0 Then
UserID = DirectCast(Dt.Rows(0)("UserID"), Integer)
Dim UserPassword As String = DirectCast(Dt.Rows(0)("UserPassword"), String)
'Dim Email As String = DirectCast(Dt.Rows(0)("Email"), String)
Session("UserPassword") = UserPassword
Label2.Text = Session("UserPassword")
Else
MessageBox.Show("UserName หรือ Email ไม่ถูกต้อง")
End If
Date :
2010-10-14 15:46:46
By :
ang89gunner
อันนี้ของ c# win app แต่เรื่องการใช้งาน system.net.mail เหมือนกันกับ web
=== การส่ง mail แบบมี attach file ด้วย free smtp (gmail) ===
Form1.Designer.cs
namespace SendMail
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.toTextBox = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.SubjectTextBox = new System.Windows.Forms.TextBox();
this.SendButton = new System.Windows.Forms.Button();
this.label3 = new System.Windows.Forms.Label();
this.fromTextBox = new System.Windows.Forms.TextBox();
this.AttachButton = new System.Windows.Forms.Button();
this.AttachLabel = new System.Windows.Forms.Label();
this.ClearButton = new System.Windows.Forms.Button();
this.AttachImage = new System.Windows.Forms.PictureBox();
this.BodyRichTextBox = new System.Windows.Forms.RichTextBox();
((System.ComponentModel.ISupportInitialize)(this.AttachImage)).BeginInit();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 40);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(23, 13);
this.label1.TabIndex = 0;
this.label1.Text = "To:";
//
// toTextBox
//
this.toTextBox.Location = new System.Drawing.Point(64, 37);
this.toTextBox.Name = "toTextBox";
this.toTextBox.Size = new System.Drawing.Size(216, 20);
this.toTextBox.TabIndex = 1;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 67);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(46, 13);
this.label2.TabIndex = 2;
this.label2.Text = "Subject:";
//
// SubjectTextBox
//
this.SubjectTextBox.Location = new System.Drawing.Point(64, 64);
this.SubjectTextBox.Name = "SubjectTextBox";
this.SubjectTextBox.Size = new System.Drawing.Size(216, 20);
this.SubjectTextBox.TabIndex = 3;
//
// SendButton
//
this.SendButton.Location = new System.Drawing.Point(205, 274);
this.SendButton.Name = "SendButton";
this.SendButton.Size = new System.Drawing.Size(75, 23);
this.SendButton.TabIndex = 5;
this.SendButton.Text = "Send";
this.SendButton.UseVisualStyleBackColor = true;
this.SendButton.Click += new System.EventHandler(this.SendButton_Click);
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(13, 13);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(33, 13);
this.label3.TabIndex = 6;
this.label3.Text = "From:";
//
// fromTextBox
//
this.fromTextBox.Location = new System.Drawing.Point(64, 10);
this.fromTextBox.Name = "fromTextBox";
this.fromTextBox.Size = new System.Drawing.Size(216, 20);
this.fromTextBox.TabIndex = 7;
//
// AttachButton
//
this.AttachButton.Location = new System.Drawing.Point(16, 90);
this.AttachButton.Name = "AttachButton";
this.AttachButton.Size = new System.Drawing.Size(75, 23);
this.AttachButton.TabIndex = 8;
this.AttachButton.Text = "Attach";
this.AttachButton.UseVisualStyleBackColor = true;
this.AttachButton.Click += new System.EventHandler(this.AttachButton_Click);
//
// AttachLabel
//
this.AttachLabel.AutoSize = true;
this.AttachLabel.Location = new System.Drawing.Point(119, 95);
this.AttachLabel.Name = "AttachLabel";
this.AttachLabel.Size = new System.Drawing.Size(53, 13);
this.AttachLabel.TabIndex = 9;
this.AttachLabel.Text = "attach file";
//
// ClearButton
//
this.ClearButton.Location = new System.Drawing.Point(205, 90);
this.ClearButton.Name = "ClearButton";
this.ClearButton.Size = new System.Drawing.Size(75, 23);
this.ClearButton.TabIndex = 10;
this.ClearButton.Text = "Clear";
this.ClearButton.UseVisualStyleBackColor = true;
this.ClearButton.Click += new System.EventHandler(this.ClearButton_Click);
//
// AttachImage
//
this.AttachImage.InitialImage = null;
this.AttachImage.Location = new System.Drawing.Point(97, 94);
this.AttachImage.Name = "AttachImage";
this.AttachImage.Size = new System.Drawing.Size(16, 16);
this.AttachImage.TabIndex = 11;
this.AttachImage.TabStop = false;
//
// BodyRichTextBox
//
this.BodyRichTextBox.BackColor = System.Drawing.SystemColors.Window;
this.BodyRichTextBox.Location = new System.Drawing.Point(15, 120);
this.BodyRichTextBox.Name = "BodyRichTextBox";
this.BodyRichTextBox.Size = new System.Drawing.Size(265, 148);
this.BodyRichTextBox.TabIndex = 13;
this.BodyRichTextBox.Text = "";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 307);
this.Controls.Add(this.BodyRichTextBox);
this.Controls.Add(this.AttachImage);
this.Controls.Add(this.ClearButton);
this.Controls.Add(this.AttachLabel);
this.Controls.Add(this.AttachButton);
this.Controls.Add(this.fromTextBox);
this.Controls.Add(this.label3);
this.Controls.Add(this.SendButton);
this.Controls.Add(this.SubjectTextBox);
this.Controls.Add(this.label2);
this.Controls.Add(this.toTextBox);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "E-Mail";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.AttachImage)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox toTextBox;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox SubjectTextBox;
private System.Windows.Forms.Button SendButton;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox fromTextBox;
private System.Windows.Forms.Button AttachButton;
private System.Windows.Forms.Label AttachLabel;
private System.Windows.Forms.Button ClearButton;
private System.Windows.Forms.PictureBox AttachImage;
private System.Windows.Forms.RichTextBox BodyRichTextBox;
}
}
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.Mail;
namespace SendMail
{
public partial class Form1 : Form
{
private const string userID = "[email protected] ";
private const string password = "xxxx";
private const string smtpServer = "smtp.gmail.com";
private const int smtpPort = 587;
private string attachPath;
public Form1()
{
InitializeComponent();
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
}
private void Form1_Load(object sender, EventArgs e)
{
attachPath = string.Empty;
fromTextBox.Text = userID;
fromTextBox.ReadOnly = true;
AttachLabel.Text = string.Empty;
AttachLabel.Hide();
AttachImage.Image = Properties.Resources.AttachIcon;
AttachImage.Hide();
ClearButton.Location = new System.Drawing.Point(16, 90);
ClearButton.Hide();
}
private void SendButton_Click(object sender, EventArgs e)
{
if (toTextBox.Text != string.Empty && SubjectTextBox.Text != string.Empty && BodyRichTextBox.Text != string.Empty)
{
MailAddress mailFrom = new MailAddress(fromTextBox.Text);
MailAddress mailTo = new MailAddress(toTextBox.Text);
MailMessage message = new MailMessage(mailFrom, mailTo);
message.IsBodyHtml = true;
message.Subject = SubjectTextBox.Text;
message.Body = BodyRichTextBox.Text;
if (attachPath != string.Empty)
message.Attachments.Add(new Attachment(attachPath));
SmtpClient client = new SmtpClient(smtpServer, smtpPort);
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential(userID, password);
try
{
client.Send(message);
MessageBox.Show(string.Format("Sent to: {0} complete.", toTextBox.Text), "สำเร็จ", MessageBoxButtons.OK, MessageBoxIcon.None);
}
catch (Exception ex)
{
MessageBox.Show(string.Format("Error: {0}", ex.Message), "ผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
}
else
{
MessageBox.Show("กรุณากรอกข้อมูลก่อน", "ผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
}
private void AttachButton_Click(object sender, EventArgs e)
{
OpenFileDialog AttachDialog = new OpenFileDialog();
AttachDialog.FileName = string.Empty;
AttachDialog.Filter = "Image Files (*.gif;*.jpg;*.png;*.bmp)|*.gif;*.jpg;*.png;*.bmp|All Files (*.*)|*.*";
AttachDialog.FilterIndex = 2;
AttachDialog.RestoreDirectory = true;
AttachDialog.Multiselect = false;
if (AttachDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
attachPath = AttachDialog.FileName;
AttachLabel.Text = (AttachDialog.SafeFileName.Length > 25) ? AttachDialog.SafeFileName.Substring(0, 14) + "..." + AttachDialog.SafeFileName.Substring(AttachDialog.SafeFileName.Length - 10) : AttachDialog.SafeFileName;
AttachLabel.Show();
AttachImage.Show();
ClearButton.Show();
AttachButton.Hide();
}
AttachDialog.Dispose();
}
private void ClearButton_Click(object sender, EventArgs e)
{
attachPath = string.Empty;
AttachLabel.Text = string.Empty;
AttachLabel.Hide();
AttachImage.Hide();
ClearButton.Hide();
AttachButton.Show();
}
}
}
ดูตรงการสร้าง mail object แล้วเอาไปใช้ใน web
Date :
2010-10-15 21:22:30
By :
tungman
Load balance : Server 00