| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1437 人关注过本帖
标题:操作数据库时的一些问题
只看楼主 加入收藏
notlook
Rank: 2
等 级:论坛游民
帖 子:73
专家分:37
注 册:2008-11-6
结帖率:80%
收藏
 问题点数:0 回复次数:11 
操作数据库时的一些问题
本人新手,最近刚接触用c#操作数据库,但老是出现问题
希望各位高手能给我举几个具体实例让我参考参考
在这里先谢谢啦
搜索更多相关主题的帖子: 数据库 
2008-11-19 00:04
_断肠人_
Rank: 1
等 级:新手上路
帖 子:85
专家分:0
注 册:2008-10-28
收藏
得分:0 
你把这个论坛的数据库研究透了就出师了

事在人为
2008-11-19 01:25
梦心
Rank: 4
来 自:福建平和
等 级:贵宾
威 望:13
帖 子:1910
专家分:0
注 册:2007-5-11
收藏
得分:0 
去CSDN下载相关的例子吧

我清高和我骄傲的倔强,在风中大声的唱:我不听,我不听~~做我自己最特别,呼呼~~啦啦~~~
我的博客园地址: [url]http://[/url]
2008-11-19 08:16
谁与争瘋
Rank: 2
等 级:论坛游民
帖 子:360
专家分:14
注 册:2008-11-18
收藏
得分:0 
不知道是否买相关书籍了

如果买了  建议照着例子多敲几遍

如果没有  那就下载点源代码看看吧

记住 学习编程的技巧就是不停的去敲击你的键盘

当你不再敲键盘的时候 有两种情况:

要么你放弃了 要么你精通了
2008-11-19 13:47
lanfeng8642
Rank: 1
来 自:广东珠海
等 级:新手上路
帖 子:37
专家分:0
注 册:2008-10-19
收藏
得分:0 
回复 4# 的帖子
说的好有道理啊

笨笨的鸟,在c#路上慢慢的飞……
2008-11-19 18:30
小仙
Rank: 7Rank: 7Rank: 7
来 自:光之谷
等 级:贵宾
威 望:39
帖 子:1812
专家分:1
注 册:2008-8-8
收藏
得分:0 
点击精华,浏览帖子,虽然不系统,择其能理解而学之,即可。


仁者乐膳,智者乐睡。我都爱~
2008-11-19 20:13
谁与争瘋
Rank: 2
等 级:论坛游民
帖 子:360
专家分:14
注 册:2008-11-18
收藏
得分:0 
斑豬說的太有道理了

2008-11-19 20:19
notlook
Rank: 2
等 级:论坛游民
帖 子:73
专家分:37
注 册:2008-11-6
收藏
得分:0 
帮我看看这段代码撒,那你有问题
提示  “WindowsApplication78.dbhelper”的类型初始值设定项引发异常。

class dbhelper
    {
        private static string connstring = "Data Sourse=.;Initial Catalog=master;Integrated Security=true";
        public static SqlConnection connection = new SqlConnection(connstring);
    }

public bool ceshi(string Userid, string Userpwd, string Userlevel)
        {
            int count = 0;
            bool ceshi = false;
            if (Userlevel == "管理员")
            {
                string sql = string.Format("select count(*) from master UserInfo where Userid='{0}' and Userpwd='{1}'", Userid, Userpwd);


                try
                {
                    SqlCommand cmd = new SqlCommand(sql, dbhelper.connection);
                    dbhelper.connection.Open();
                    count = (int)cmd.ExecuteScalar();
                    if (count == 1)
                    {
                        ceshi = true;
                    }
                    else
                    {
                        MessageBox.Show("用户名或密码不存在");
                        ceshi = false;

                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    dbhelper.connection.Close();
                }
            }
            return ceshi;
        }

        private void button1_Click(object sender, EventArgs e)
        {
           if(ceshi(username.Text,password.Text,userleixing.Text))
           {
               MessageBox.Show("登陆成功");
           }
        }


还有这段
为什么提示UserInfo无效,UserInfo明明有的啊

 public bool ceshi()
        {
            int count = 0;
            bool ceshi = false;
            string UserName = username.Text;
            string number = password.Text;
            string leixing = userleixing.Text;
            if (leixing == "管理员")
            {

                string aa = "Data Source=.;Initial Catalog=master;Integrated Security=true";
                SqlConnection con = new SqlConnection(aa);
                con.Open();
                string sql = string.Format("Select count(*) from UserInfo where Userid='{0}'and Userpwd='{1}'", UserName, number);
                SqlCommand cmd = new SqlCommand(sql, con);
                count = (int)cmd.ExecuteScalar();
                try
                {

                    if (count == 1)
                    {
                        ceshi = true;
                    }
                    else
                    {
                        MessageBox.Show("账户或密码错误");
                        ceshi = false;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    con.Close();
                }
            }
            return ceshi;
        }
 private void button1_Click(object sender, EventArgs e)
        {
            if (ceshi())
            {
                MessageBox.Show("成功");
            }
        }
2008-11-24 22:08
andy560225
Rank: 1
来 自:天上
等 级:新手上路
帖 子:72
专家分:0
注 册:2008-10-29
收藏
得分:0 
去找找我发的帖子吧
都是新手连数据库的

我知道我笨,可是我很勤劳
妈妈说:"早起的鸟有虫吃"!
2008-11-25 10:31
notlook
Rank: 2
等 级:论坛游民
帖 子:73
专家分:37
注 册:2008-11-6
收藏
得分:0 
按照楼上帖子里的写法还是会出现  提示UserInfo无效的错误
是不是数据库有问题啊??
string uname = this.textbox1.Text.ToString();
            string upassword = this.textbox2.Text.ToString();
            SqlConnection thisconnection = new SqlConnection(@"Server=.;Integrated Security=True;" + "DataBase=master");
            thisconnection.Open();
            SqlCommand thiscommand = thisconnection.CreateCommand();
             = "select Userid,Userpwd from UserInfo where Userid='" + uname + " '";
            SqlDataReader thisreader = thiscommand.ExecuteReader();
            if (thisreader.Read())
            {
                if (thisreader["upassword"].ToString().Trim() == upassword)
                {
                    MessageBox.Show("恭喜您登陆成功!", "登陆成功!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    //yhxx tt = new yhxx();
                    //tt.Show();

                }
                else { MessageBox.Show("密码错误,请重新输入!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information); }

            }
            else { MessageBox.Show("此用户不存在,请您注册!", "注册", MessageBoxButtons.OK, MessageBoxIcon.Information); }
            thisconnection.Close();
            thisreader.Close();
2008-11-25 17:39
快速回复:操作数据库时的一些问题
数据加载中...
 
   



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

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