本文介绍了我遇到c#代码有问题,任何人都可以帮助我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我执行我的代码时,我得到了这个。是什么意思???
System.Data.SqlClient.SqlException(0x80131904):在预期条件的上下文中指定的非布尔类型的表达式,接近'1'。 />
添加评论代码
When i execute my code I get this. what does it mean???
System.Data.SqlClient.SqlException (0x80131904): An expression of non-boolean type specified in a context where a condition is expected, near '1'.
[edit] Added code from comment
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApplication9
{
public partial class Form1 : Form
{
SqlConnection con;
SqlCommand cmd;
SqlDataReader dr;
string SqlStr;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
con = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=employee;Integrated Security=True");
//textBox1.Text = con.ConnectionString;
con.Open();
cmd = con.CreateCommand();
cmd.CommandText = "Select Empno,Ename,Job,Salary From Emplye Order By Empno";
dr = cmd.ExecuteReader();
ShowData();
}
private void ShowData()
{
if (dr.Read())
{
textBox1.Text = dr[0].ToString();
textBox2.Text = dr[1].ToString();
textBox3.Text = dr[2].ToString();
textBox3.Text = dr[3].ToString();
}
else MessageBox.Show("No data exists.");
}
private void button1_Click(object sender, EventArgs e)
{
ShowData();
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text=textBox2.Text=textBox3.Text=textBox4.Text="";
dr.Close();
cmd.CommandText="select IsNULL(Max(Empno),1000)+1 From Emplye";
textBox1.Text=cmd.ExecuteScalar().ToString();
button3.Enabled = true;
textBox2.Focus();
}
private void ExecuteDML()
{
DialogResult d = MessageBox.Show("Are you sure of executing the below Sql Statement?\n\n" + SqlStr, "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (d == DialogResult.Yes)
{
cmd.CommandText = SqlStr;
int count = cmd.ExecuteNonQuery();
if (count > 0) MessageBox.Show("Statement excuted successfully");
else
MessageBox.Show("Statement failed execution");
ShowData();
}
}
private void button3_Click(object sender, EventArgs e)
{
SqlStr="Insert Emplye(Empno,Ename,Job,Salary)Values("+textBox1.Text+",'"+textBox2.Text+"'.'"+textBox3.Text+"',"+textBox4.Text+")";
ExecuteDML();
}
private void button4_Click(object sender, EventArgs e)
{
SqlStr="Update Emplye Set Ename='"+textBox2.Text+"',Job='"+textBox3.Text+"',salary="+textBox4.Text+"where Empno+"+textBox1.Text;dr.Close();
ExecuteDML();
}
private void button5_Click(object sender, EventArgs e)
{
SqlStr="Delete From Employe where Empno="+textBox1.Text;
dr.Close();
ExecuteDML();
}
private void button6_Click(object sender, EventArgs e)
{
if(con.State != ConnectionState.Closed)
{
con.Close();
}
this.Close();
}
}
}
[/ edit]
[/edit]
推荐答案
private void button4_Click(object sender, EventArgs e)
{
SqlStr="Update Emplye Set Ename='"+textBox2.Text+"',Job='"+textBox3.Text+"',salary="+textBox4.Text+"where Empno = "+textBox1.Text;
dr.Close();
ExecuteDML();
}
这篇关于我遇到c#代码有问题,任何人都可以帮助我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!