回 帖 发 新 帖 刷新版面

主题:急待求解!c#数据不能更新问题

为什么数据库不能随着textbox添加的数据一起更新呢,从新启动后数据库还是原来的样子,不能更新,添加啊,急啊,请大侠帮助一下[em14][em14]下面是我写的代码
private void butADD_Click(object sender, EventArgs e)
        {/*
            string connnectionString =@" Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\database\SuperMarket.mdf;Integrated Security=True;User Instance=True";
            SqlConnection conn = new SqlConnection(connnectionString);
            conn.Close();
            StringBuilder str = new StringBuilder();
            str.Append("INSERT INTO GoodsTable(商品编号,商品名称,供应价格,供应商,供应日期)");
            str.Append("VALUES('" + Convert.ToInt32(gnubtextBox.Text.ToString()) + "','" + gnamtextBox.ToString() + "','" + Convert.ToSingle(gpritextBox.Text.ToString()) + "','" + gmaktextBox.Text.ToString() + "','" + Convert.ToDateTime(gdattextBox.Text) + "')");
            SqlCommand cmd = new SqlCommand(str.ToString(), conn);
                conn.Open();
                cmd.ExecuteNonQuery();
                MessageBox.Show("OK");
                conn.Close();
               */



这是第二种写法,也是不能实现,求解啊!!!!
            try
            {
                string connnectionString = @" Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\database\SuperMarket.mdf;Integrated Security=True;User Instance=True";
                string insert = "INSERT INTO GoodsTable(商品名称, 商品编号, 供应价格, 供应商, 供应日期) VALUES ('" + gnamtextBox.Text + "', " + Convert.ToInt32(gnubtextBox.Text.ToString()) + ", " + Convert.ToSingle(gpritextBox.Text.ToString()) + ", '" + gmaktextBox.Text + "', " + gdattextBox.Text + ")";
                SqlConnection conn = new SqlConnection(connnectionString);
                conn.Open();
                using (SqlCommand cmd = new SqlCommand(insert, conn))
                {
                    cmd.ExecuteNonQuery();
                    cmd.Dispose();
                }

                conn.Close();

            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }


        }

回复列表 (共1个回复)

沙发


[url=http://www.mycheapgolf.com]Cheap golf clubs[/url]
[url=http://www.mycheapgolf.com]Cheap golf irons[/url]
[url=http://www.mycheapgolf.com]Cheap Golf Drivers[/url]
[url=http://www.mycheapgolf.com/goods-10882-wholesale-cheap-Ping-K15-Driver-on-sale.html]Ping K15 Driver[/url]
[url=http://www.mycheapgolf.com/goods-10973-wholesale-cheap-TaylorMade-R11-Driver-on-sale.html]TaylorMade R11 Driver[/url]
[url=http://www.wowoshoes.com]wholesale jordan shoes[/url]
[url=http://www.wowoshoes.com]wholesale nike shoes[/url]
[url=http://www.wowoshoes.com]wholesale nike air max shoes[/url]
[url=http://www.wowoshoes.com]wholesale gucci[/url]
[url=http://www.airmaxclubs.com]cheap nike air max shoes[/url]
[url=http://www.boots4world.com]Timberland men's shoes[/url]
[url=http://www.cheapguccishoe.com]cheap gucci[/url]
[url=http://www.mycheapfashion.com]cheap MBT shoes[/url]
[url=http://www.mycheapsupra.com]Supra UK[/url]

我来回复

您尚未登录,请登录后再回复。点此登录或注册