| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 735 人关注过本帖
标题:为什么添加不了数据呢
只看楼主 加入收藏
apple0129
Rank: 1
等 级:新手上路
帖 子:39
专家分:0
注 册:2008-3-28
收藏
 问题点数:0 回复次数:4 
为什么添加不了数据呢
我通过一个添加按钮向数据库中添加数据,不报错,但是数据库中没有数据,是怎么回事啊
我的代码如下:
private void btnadd_Click(object sender, System.EventArgs e)
        {   SqlConnection sqlcon = new SqlConnection("server=.;database=peisong; uid=sa;pwd=;");//创建SqlConnection对象
            sqlcon.Open();
            SqlCommand cmd = new SqlCommand();
         into user values (@username,@storename,@post,@powerid,@dlname,@pwd,"
            +"@sex,@birthday,@cardid,@ustelephone,@usaddress)";
        cmd.Parameters.Add("@username",username.Text.ToString());
        cmd.Parameters.Add("@storename",this.store.SelectedItem.Value);
        cmd.Parameters.Add("@post",this.post.SelectedItem.Value);
        cmd.Parameters.Add("@powerid",this.power.SelectedItem.Value);
        cmd.Parameters.Add("@dlname",dlname.Text.ToString());
        cmd.Parameters.Add("@pwd",pwd.Text.ToString());
        cmd.Parameters.Add("@sex",this.sex.SelectedItem.Value);
        cmd.Parameters.Add("@birthday",DateTime.Now);
        cmd.Parameters.Add("@cardid",cardid.Text.ToString());
        cmd.Parameters.Add("@ustelephone",tel.Text.ToString());
        cmd.Parameters.Add("@usaddress",address.Text.ToString());
            cmd.Connection=sqlcon;
            cmd.ExecuteNonQuery();
            sqlcon.Close();
搜索更多相关主题的帖子: 数据 
2008-04-20 22:08
残影留香
Rank: 1
来 自:广西南宁
等 级:新手上路
帖 子:193
专家分:0
注 册:2008-3-19
收藏
得分:0 
你这个commandType属性没有设置
2008-04-21 09:26
guaishi
Rank: 1
等 级:新手上路
帖 子:156
专家分:0
注 册:2007-6-15
收藏
得分:0 
我也添加不了数据,没有报任何错误码
using System;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using
using
using System.Text;


public partial class support : System.Web.UI.Page
{

    protected void ibt_Click(object sender, ImageClickEventArgs e)
    {
        string kkwd = kwd.Text.Trim().Replace("’", "'");
        if (kkwd != string.Empty || kkwd != null)
        {
            Response.Redirect("ppsearch.aspx?kwd=" + kkwd);
        }
        else
        {

        }
    }

    protected void tijiao_Click(object sender, EventArgs e)
    {
        //string company = Request["company"];
        //string first = Request["first"];
        //string last = Request["last"];
        //string phone = Request["phone"];
        //string fax = Request["fax"];
        //string email = Request["email"];
        //string product = Request["product"];
        //string type = Request["type"];
        //string title = Request["tile"];
        //string message = Request["message"];

        string cons = "Provider=Microsoft.Jet.OleDb.4.0;";
        // Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\website1\#db1.aspx;Persist Security Info=False
        cons += "Data Source=";
        cons += MapPath("#db1.aspx");
        cons += ";Persist Security Info=False";
        try
        {
            OleDbConnection scon = new OleDbConnection(cons);
            scon.Open();
            OleDbCommand scom = new OleDbCommand();
            scom.Connection = scon;
             = "Insert into forback(Company,First,Last,Phone,Fax,Email,Product,Type,Title,Message)values('" + company.Text + "','" + first.Text + "','" + last.Text + "','" + phone.Text + "','" + fax.Text + "','" + email.Text + "','" + product.Text + "','" + tile.Text + "','" + type.Items + "''" + message.Text + "')";
            //OleDbCommand odd = new OleDbCommand(selstr, odc);
            scom.ExecuteNonQuery();
            Response.Redirect("index.aspx");
            int count = scom.ExecuteNonQuery();

            if (count > 0)
            {
                //MessageBox.Show("添加成功!");
                scon.Close();
                Response.Redirect("index.aspx");
            }
            else
            {
               
                //MessageBox.Show("添加失败!");
            }
        }

        catch (Exception ee)
        {
            //MessageBox.Show(ee.Message.ToString());
        }
    }
}

网络改变了我,编程改变了我的生活
2008-04-22 17:23
yiyihui82
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2008-4-10
收藏
得分:0 
断点调试一下, 都运行了吗?
2008-04-22 18:09
guaishi
Rank: 1
等 级:新手上路
帖 子:156
专家分:0
注 册:2007-6-15
收藏
得分:0 
都可以运行

网络改变了我,编程改变了我的生活
2008-04-27 12:37
快速回复:为什么添加不了数据呢
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.029911 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved