2 emilylai Emilylai 于 2015.06.04 18:00 提问

请问一下在.net中这样的错误怎么解决?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace KTV前台
{
public partial class 包场模式 : Form
{
public 包场模式()
{
InitializeComponent();
}
SqlConnection conn = new SqlConnection("server=.;database=ktv;integrated security=true;");
private void 选择包间_Load(object sender, EventArgs e)
{

    }

    private void button2_Click(object sender, EventArgs e)
    {
        if (textBox1.Text == "")
        {
            MessageBox.Show("请输入房间号!", "提示");
        }
        else
        {
            conn.Open();
            if (comboBox3.Text == "上午场(8:00---12:00)")
            {
                 SqlCommand a = new SqlCommand("Select * from 房间信息 where 房间ID='"+textBox1.Text +"'",conn);
                 a.ExecuteNonQuery();
                 SqlCommand com = new SqlCommand("insert into 房间信息(模式,小时数,总价) values('" + comboBox3.Text + "','4','300') ", conn);
                com.ExecuteNonQuery();
                MessageBox.Show("添加成功", "提示");

            }
            else if (comboBox3.Text == "下午场(12:30---5:30)")
            {
                SqlCommand com = new SqlCommand("insert into 房间信息(模式,小时数,总价)values('" + comboBox3.Text + "','5','400')", conn);
                com.ExecuteNonQuery();
                MessageBox.Show("添加成功", "提示");


            }
            else if (comboBox3.Text == "黄金场(7:00---12:00)")
            {
                SqlCommand com = new SqlCommand("insert into 房间信息(房间ID,模式,小时数,总价) values('" + textBox1.Text + "','" + comboBox3.Text + "','5','1000')", conn);
                com.ExecuteNonQuery();
                MessageBox.Show("添加成功", "提示");


            }
            else if (comboBox3.Text == "午夜场(12:30--5:00)")
            {
                SqlCommand com = new SqlCommand("insert into 房间信息(房间ID,模式,小时数,总价) values('" + textBox1.Text + "','" + comboBox3.Text + "','5','300')", conn);
                com.ExecuteNonQuery();
                MessageBox.Show("添加成功", "提示");

            }
            conn.Close();
        }
    }
}

}

图片说明

1个回答

caozhy
caozhy   Ds   Rxr 2015.06.04 18:05
已采纳

检查数据库中有没有模式这一列。它的类型和你用的类型是否相符。

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!