标题:关于数据库连接于操作的问题
只看楼主
给我毅刀
Rank: 1
等 级:新手上路
帖 子:30
专家分:9
注 册:2012-9-2
 问题点数:0 回复次数:2 
关于数据库连接于操作的问题
小弟最近看了一段程序
 namespace bookmis
{
    public partial class logon : Form
    {
        public logon()
        {
            InitializeComponent();
        }

        private void btnlogon_Click(object sender, EventArgs e)
        {
            SqlConnection sqlcon = new SqlConnection("data source=localhost;Initial catalog=Bookstore;Integrated security=sspi;");

            string str = "insert into dbo.读者 values(@loginname,@loginpassword)";//这两个是哪里来的啊
            sqlcon.Open();
            SqlCommand cmd = new SqlCommand(str, sqlcon);
            cmd.Parameters.Add("@loginname", SqlDbType.NChar, 20);
            cmd.Parameters.Add("@loginpassword", SqlDbType.NChar, 20);
            cmd.Parameters["@loginname"].Value = tBoxuser.Text;
            cmd.Parameters["@loginpassword"].Value = tBoxpassword.Text;
            cmd.ExecuteNonQuery();
            sqlcon.Close();
            MessageBox.Show("注册成功");
            this.tBoxuser.Clear();
            this.tBoxpassword.Clear();
        }
    }
}
怎么会连不上数据库呢,不显示messagebox啊,数据库名bookstore,表名读者,步骤好像也对,可就是点了button没反应。谁能指教一下啊
还有 cammand对象的 paramerers 方法什么意思啊  怎么使用啊 请指教一下
搜索更多相关主题的帖子: localhost 数据库连接 security private public 
2013-06-21 18:14
QJlin
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:3
帖 子:186
专家分:560
注 册:2013-5-18
得分:0 
string connestring = "Data Source=WIN-08OC9UFPA79;Initial Catalog=school1;Integrated Security=True";
        SqlConnection connection;
        SqlCommand command;
connection = new SqlConnection(connestring);
 connection.Open();
 string str = "insert into dbo.读者 values(@loginname,@loginpassword)";//这两个是哪里来的啊 dbo.读者这个表里的两个属性!
 SqlCommand cmd = new SqlCommand(str, sqlcon);//执行命令,也就是SQL语句;

慢慢前进走,不求一步登天,只求慢慢前进
2013-06-21 18:42
杰与贤3
Rank: 2
等 级:论坛游民
帖 子:11
专家分:18
注 册:2013-5-17
得分:0 
string connestring = "Data Source=.;Initial Catalog=bookstore;Integrated Security=True";
        SqlConnection connection;
        SqlCommand command;
connection = new SqlConnection(connestring);
connection.Open();
string str = "insert into dbo.读者 values(@loginname,@loginpassword)";
SqlCommand cmd = new SqlCommand(str, sqlcon);

cmd.Parameters.Add("@loginname", SqlDbType.NChar, 20);
            cmd.Parameters.Add("@loginpassword", SqlDbType.NChar, 20);
            cmd.Parameters["@loginname"].Value = tBoxuser.Text;
            cmd.Parameters["@loginpassword"].Value = tBoxpassword.Text;
            cmd.ExecuteNonQuery();
            sqlcon.Close();
            MessageBox.Show("注册成功");
            this.tBoxuser.Clear();
            this.tBoxpassword.Clear();
2013-06-22 10:09



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-415765-1-1.html




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

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