我正在尝试从我的项目发送电子邮件,但我遇到了一些麻烦......
我正在使用此代码:
private void SendMail()
{
MailMessage mail = new MailMessage(MailSender, MailReciever, MailSubject, MailContent);
SmtpClient client = new SmtpClient(SMTPServer);
client.Send(mail);
}
Run Code Online (Sandbox Code Playgroud)
然后我得到一个例外:
SMTP服务器需要安全连接或客户端未经过身份验证.服务器响应为:5.7.1客户端未经过身份验证
我不知道该怎么办.有什么建议 ?我究竟做错了什么 ?
到目前为止,这是代码的一部分:
System.IO.FileInfo[] fileNames = dirInfo.GetFiles("*.*");
foreach (System.IO.FileInfo fi in fileNames)
{
Console.WriteLine("{0}: {1}: {2}", fi.Name, fi.LastAccessTime, fi.Length);
}
System.IO.DirectoryInfo[] dirInfos = dirInfo.GetDirectories("*.*");
foreach (System.IO.DirectoryInfo d in dirInfos)
{
Console.WriteLine(d.Name);
}
Run Code Online (Sandbox Code Playgroud)
我想要的是输出如下: Total files: 49
我该如何显示49?
我正在尝试使用Visual Basic 2012上的C#创建注册页面.当我调试时,我得到0错误,但是当我尝试注册帐户时,我收到以下错误.
"'附近的语法不正确')'"
如果我尝试使用现有用户名创建帐户,则表示该用户名已存在.所以我能够连接到SQL服务器,但我不确定我哪里出错了.
此注册页面应在我的DB DNMembership> Table> Accounts中创建帐户
这是我正在使用的代码.
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["RegDNMembershipConnectionString"].ConnectionString);
con.Open();
string insCmd = "Insert into Accounts (AccountName, Passphrase, EmailAddress, FullName, Country)";
SqlCommand insertUser = new SqlCommand(insCmd, con);
insertUser.Parameters.AddWithValue("@AccountName", TextBoxUN.Text);
insertUser.Parameters.AddWithValue("@Passphrase", TextBoxPass.Text);
insertUser.Parameters.AddWithValue("@EmailAddress", TextBoxEA.Text);
insertUser.Parameters.AddWithValue("@FullName", TextBoxFN.Text);
insertUser.Parameters.AddWithValue("@Country", DropDownListCountry.SelectedItem.ToString());
try
{
insertUser.ExecuteNonQuery();
con.Close();
Response.Redirect("Login.aspx");
}
catch(Exception er)
{
Response.Write("<b>Something Really Bad Happened... Please Try Again.< /br></b>");
Response.Write(er.Message);
}
Run Code Online (Sandbox Code Playgroud)
我做错了什么?
private void InvoiceForm_Load(object sender, EventArgs e)
{
comboBox2.Focus();
lstinv = invhnd.Get();// lstinv is inventry type list
comboBox2.DataSource = lstinv;
comboBox2.DisplayMember = "ItemName";
comboBox2.ValueMember = "ItemPrice";
}
Run Code Online (Sandbox Code Playgroud) public bool location()
{
string OUI = "OUI";
SqlConnection con = new SqlConnection(@"Data Source=WIN-218NC1F1FE2\SQLEXPRESS;Initial Catalog=projet;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("select max(id_reservation) from reservation");
cmd.Connection = con;
Int32 maxId = (Int32)cmd.ExecuteScalar();
string v = Convert.ToString(maxId);
//correct
SqlCommand q = new SqlCommand("insert into reservation(location) values('" + OUI + "') where id_reservation ='"+ maxId + "'", con);
SqlDataReader da = q.ExecuteReader();
return true ;
}
Run Code Online (Sandbox Code Playgroud)
问题在命令中:关键字'where'附近的语法不正确.救命 !!!
下面列出了已知的格式
dd/mm/yyyy (01/01/2015)
d/m/yyyy (1/1/2015)
dd/mm/yy (01/01/15)
d/m/yy (1/1/15)
Run Code Online (Sandbox Code Playgroud)
其他变体将破折号( - ),点(.)或空格作为字段分隔符.
我正在考虑为每个模式创建一个正则表达式以保持其可维护性,但不确定是否有更好的解决方案.请分享是否有更好的解决方案.
更新: 日期是大文本的一部分,在从文本中提取潜在的日期列表之前,我无法使用DateTime.TryParseExact.
我试图解析以下内容 09/04/2015 17:22:29.183 PM
代码如下:
string s = "09/04/2015 17:22:29.183 PM";
DateTime.ParseExact(s,Constants.DateTimeFormat,System.Globalization.CultureInfo.InvariantCulture);
Run Code Online (Sandbox Code Playgroud)
该DateTimeFormatIS形式的dd/MM/yyyy hh:mm:ss.fff tt
但是编译器会抛出错误.我哪里错了?
我在数据库中的价值如下:
04/14
01-15
02/15
Run Code Online (Sandbox Code Playgroud)
我需要将这些值解析为数据时间格式.即使从04/14成为01/04/2014,也没关系.
我试过下面哪个不行.
var strDate = "04/14";
var format = "d";
var provider = CultureInfo.InvariantCulture;
var result = DateTime.ParseExact(strDate, format, provider);
Run Code Online (Sandbox Code Playgroud) 代码下面的swift有错误,我假设我不能在'if'语句中使用比较运算符...?
我收到错误
如果我尝试使用&&或||,则"一元运算符不能与其操作数分离" 在第一个'else'声明之后.
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)
{
if (row < 8)
{
self.pickerLabel.text = "Too cold";
}
else if(row >= 8 && <= 10) // Error occurs here...
{
self.pickerLabel.text = "Just right";
}
else if(row == 12)
{
self.pickerLabel.text = "Too warm";
}
else
{
view.backgroundColor = UIColor.blueColor();
}
}
Run Code Online (Sandbox Code Playgroud)
是否有解决方案可以让我解决任何人都知道的错误?
谢谢.
如果在使用语句中使用了Stream Writer,则即使没有要写的内容,Stream Writer也会创建一个文件,Reason在块的末尾使用块调用dispose方法.
代码是
using (StreamWriter sw = new StreamWriter(@"d:\abc.txt"))
{
}
Run Code Online (Sandbox Code Playgroud)
如果没有什么可写的,我不会创建空白文件.我正在寻找的原因是我们有条件地写日志.