它是我的编码,但数据不是数据库中的sumit和eamail plz帮助我 [英] it my coding but data is not sumit in databse and eamail plz help me

查看:109
本文介绍了它是我的编码,但数据不是数据库中的sumit和eamail plz帮助我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  protected   void  btnSubmit_Click(对象发​​件人,EventArgs e)
{
string qry = 插入nproject值(@ Email,projectname,@ Designation,@ Date,@ AboutUser);
SqlConnection connectio = new SqlConnection( @ 数据源= FARRUKH-PC\FARRUKH;初始目录=项目;集成安全性=真);
SqlDataAdapter Sda = new SqlDataAdapter();

connectio.Open();
SqlCommand cmd = new SqlCommand(qry,connectio);
cmd.Parameters.AddWithValue( Email,txtTo.Text);
cmd.Parameters.AddWithValue( projectname,txtprojectname.Text);
cmd.Parameters.AddWithValue( Designation,txtdesignation.Text);
cmd.Parameters.AddWithValue( Date,txtdate.Text);
cmd.Parameters.AddWithValue( AboutUser,txtaboutuser.Text);


cmd.ExecuteNonQuery();

connectio.Close();
Response.Write( successl saved);
}

受保护 void Sendingemial()
{
try
{

MailAddress SendTo = new MailAddress(txtTo.Text);

MailMessage mail = new MailMessage();

mail.From = new MailAddress( );
mail.To.Add( );

SmtpClient smtp = new SmtpClient();
smtp.Host = smtp.gmail.com; // 或您的SMTP服务器地址
smtp.Credentials = new System.Net.NetworkCredential
waqasvxpz@gmail.com, videoexpertz001);
// 或者您的Smtp电子邮件ID和密码
smtp.EnableSsl = < span class =code-keyword> true
;
smtp.Send(mail);
}

catch (例外情况)
{
}
}
}

解决方案

您需要在参数上使用''@'来将名称与其值相关联:

  string  qry =   INSERT INTO nproject VALUES(@ Email,@ projectname,@ Designation,@ Date,@ AboutUser); 
SqlConnection connectio = new SqlConnection( @ 数据源= FARRUKH-PC\FARRUKH;初始目录=项目;集成安全性=真);
SqlDataAdapter Sda = new SqlDataAdapter();

connectio.Open();
SqlCommand cmd = new SqlCommand(qry,connectio);
cmd.Parameters.AddWithValue( @ Email,txtTo.Text);
cmd.Parameters.AddWithValue( @ projectname,txtprojectname.Text);
cmd.Parameters.AddWithValue( @ Designation,txtdesignation.Text);
cmd.Parameters.AddWithValue( @ Date,txtdate.Text);
cmd.Parameters.AddWithValue( @ AboutUser,txtaboutuser.Text);

另外,在INSERT查询中不列出字段名称是一个坏主意:它依赖于不包含其他字段(例如初始ID字段)的表定义以及当前的顺序田野。



请停止吞咽异常 - 如果你这样做,那么你就丢掉了找到问题所需的信息!你有多少次被告知这是一个坏主意?因为我知道我今天早些时候告诉过你! :笑:


protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string qry = " insert into nproject values (@Email,projectname,@Designation,@Date,@AboutUser)";
        SqlConnection connectio = new SqlConnection(@"Data Source=FARRUKH-PC\FARRUKH;Initial Catalog=Project;Integrated Security=True");
        SqlDataAdapter Sda = new SqlDataAdapter();

        connectio.Open();
        SqlCommand cmd = new SqlCommand(qry, connectio);
        cmd.Parameters.AddWithValue("Email", txtTo.Text);
        cmd.Parameters.AddWithValue("projectname", txtprojectname.Text);
        cmd.Parameters.AddWithValue("Designation", txtdesignation.Text);
        cmd.Parameters.AddWithValue("Date", txtdate.Text);
        cmd.Parameters.AddWithValue("AboutUser", txtaboutuser.Text);


        cmd.ExecuteNonQuery();

        connectio.Close();
        Response.Write("successfull saved");
    }

    protected void Sendingemial()
    {
        try
        {

            MailAddress SendTo = new MailAddress(txtTo.Text);

            MailMessage mail = new MailMessage();

            mail.From = new MailAddress("");
            mail.To.Add("");

            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address
            smtp.Credentials = new System.Net.NetworkCredential
                ("waqasvxpz@gmail.com, ", "videoexpertz001");
            //Or your Smtp Email ID and Password
            smtp.EnableSsl = true;
            smtp.Send(mail);
        }

        catch (Exception ex)
        {
        }
    }
}

解决方案

You need an ''@'' on the parameters to tie the names together with their values:

string qry = "INSERT INTO nproject VALUES (@Email,@projectname,@Designation,@Date,@AboutUser)";
SqlConnection connectio = new SqlConnection(@"Data Source=FARRUKH-PC\FARRUKH;Initial Catalog=Project;Integrated Security=True");
SqlDataAdapter Sda = new SqlDataAdapter();
 
connectio.Open();
SqlCommand cmd = new SqlCommand(qry, connectio);
cmd.Parameters.AddWithValue("@Email", txtTo.Text);
cmd.Parameters.AddWithValue("@projectname", txtprojectname.Text);
cmd.Parameters.AddWithValue("@Designation", txtdesignation.Text);
cmd.Parameters.AddWithValue("@Date", txtdate.Text);
cmd.Parameters.AddWithValue("@AboutUser", txtaboutuser.Text);

In addition, it is a poor idea to not list the names of the fields in your INSERT query: it relies on the table definition containing no other fields (such as an initial ID field) and on the current order of the fields.

Please, stop swallowing exceptions - if you do that, then you throw away information you need to find the problem! How many times do you have to be told that this is a bad idea? Because I know I have told you earlier today! :laugh:


这篇关于它是我的编码,但数据不是数据库中的sumit和eamail plz帮助我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆