| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2322 人关注过本帖
标题:为什么连接不到数据库
只看楼主 加入收藏
编程3869768
Rank: 1
等 级:新手上路
帖 子:55
专家分:0
注 册:2008-3-25
结帖率:100%
收藏
 问题点数:0 回复次数:7 
为什么连接不到数据库
我做啦一个数据库 Text   在windows 应用程序下  
通过用户界面  进行添加, 删除  不知道哪里出啦问题
总是连接不到数据库 郁闷   
图片附件: 游客没有浏览图片的权限,请 登录注册

帮我看看  
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private SqlConnection myConnection;
        private SqlCommand myCommand;

        private void Form1_Load(object sender, EventArgs e)
        {
            myConnection = new SqlConnection ("data source=(.);Initial Catalog=Text;Integrated Security=SSPI ");
               
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                myConnection.Open();
                string sql = "insert into Passenger_table values('" + this.textBox1.Text + " ','" + this.textBox2.Text + " ','" + this.textBox3.Text + " ','" + this.textBox4.Text + "','" + this.textBox5.Text + "')";
                myCommand = new SqlCommand(sql, myConnection);
                myCommand.ExecuteNonQuery();
                MessageBox.Show("插入成功");
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                myConnection.Close();
            }
            
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {

        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            




        }

        private void textBox5_TextChanged(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                myConnection.Open();
                myCommand = new SqlCommand("delect * from Passenger_table where flightID='" + textBox1 + "'", myConnection);
                myCommand.ExecuteNonQuery();
                MessageBox.Show("删除成功");
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                myConnection.Close();
            }
           
 
        
        }
    }
}
搜索更多相关主题的帖子: 数据库 
2008-11-22 14:07
小仙
Rank: 7Rank: 7Rank: 7
来 自:光之谷
等 级:贵宾
威 望:39
帖 子:1812
专家分:1
注 册:2008-8-8
收藏
得分:0 
data source=(.);改成server = .;试下,晕
ADO的帖子发到这来了。


仁者乐膳,智者乐睡。我都爱~
2008-11-22 14:13
编程3869768
Rank: 1
等 级:新手上路
帖 子:55
专家分:0
注 册:2008-3-25
收藏
得分:0 

LZ  
太感谢啦    成功啦
对啦 可以告诉我为什么 这样吗  
我写的 在语法上没有问题啦  
data source=(.)   和 server=.    为什么  改变这么一点  
就有这么大的区别
请解释一下
2008-11-22 14:54
小仙
Rank: 7Rank: 7Rank: 7
来 自:光之谷
等 级:贵宾
威 望:39
帖 子:1812
专家分:1
注 册:2008-8-8
收藏
得分:0 
你就这样记好了。。
我也不清楚它为什么要这样。。


仁者乐膳,智者乐睡。我都爱~
2008-11-22 22:01
dxformat
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2005-1-12
收藏
得分:0 
呵呵,server=. 这是标准格式,我记得书上就是这样教的,没啥为什么,就是这种写法
2008-11-27 08:54
mc20421219
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2008-12-8
收藏
得分:0 
顶!
2008-12-09 15:22
球球
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:1146
专家分:265
注 册:2005-11-28
收藏
得分:0 
哈哈。。。~~

好累
2008-12-10 00:12
快速回复:为什么连接不到数据库
数据加载中...
 
   



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

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