就是我查询出数据出来 然后修改 就会报错,无限数据类型下面附代码窗体代码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.OracleClient;
using System.Data.OleDb;
using System.Data.Odbc;namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{ if (textBox1.Text == "")
{
MessageBox.Show("请输入查询条件!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return;
} int id = Convert.ToInt32(textBox1.Text);
string sql = string.Format("select em_house_t.p_priv_flarea,em_house_t.p_co_flarea,em_house_t.p_ratial,em_house_t.p_flarea,em_house_t.FLAREA,em_house_t.PRIV_FLAREA,em_house_t.RATIAL,em_house_t.CO_FLAREA,em_house_t.FLAREA,em_location_t.LOCATION_NAME from em_house_t,em_location_t,EM_FLAT_LOC_T" +
" where em_house_t.HOUSE_ID= em_flat_loc_t.HOUSE_ID and" +
" em_location_t.LOCATION_ID=em_flat_loc_t.LOCATION_ID and em_house_t.HOUSE_ID='{0}'", id);
try
{
OracleDataReader dReader = DBHelp.ExcuterRead(sql);
if (dReader.Read())
{ this.textBox2.Text = dReader["p_priv_flarea"].ToString();
this.textBox3.Text = dReader["p_co_flarea"].ToString();
this.textBox4.Text = dReader["p_ratial"].ToString();
this.textBox5.Text = dReader["p_flarea"].ToString();
this.textBox6.Text = dReader["PRIV_FLAREA"].ToString();
this.textBox7.Text = dReader["LOCATION_NAME"].ToString();
this.textBox8.Text = dReader["RATIAL"].ToString();
this.textBox9.Text = dReader["CO_FLAREA"].ToString();
this.textBox10.Text = dReader["FLAREA"].ToString();
}
else
{
MessageBox.Show("没有你要查找的数据", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
} dReader.Close();
}
catch (Exception ex)
{ MessageBox.Show(ex.Message);
}
finally
{
DBHelp.conn.Close();
}
}
//修改 测试id 2289343
private void button2_Click(object sender, EventArgs e)
{
int id = Convert.ToInt32(textBox1.Text); string sql = string.Format("update em_house_t set PRIV_FLAREA='{0}',RATIAL='{1}',CO_FLAREA='{2}',FLAREA='{3}',p_priv_flarea='{4}',p_co_flarea='{5}',p_ratial='{6}',p_flarea='{7}' where house_id='{8}'", textBox6.Text, textBox8.Text, textBox9.Text, textBox10.Text,textBox2.Text,textBox3.Text,textBox4.Text,textBox5.Text, id);
try
{
//OracleDataReader dReader = DBHelp.ExcuterRead(sql); int reulet =Int32.Parse( DBHelp.ExcutSslet(sql).ToString());
if (reulet != 1)
{
MessageBox.Show("修改失败!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("修改成功!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (Exception ee)
{
MessageBox.Show(ee.Message);
}
} }
}
DBHelp 类using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OracleClient;
using System.Windows.Forms;
using System.Data;
//System.Data.ConnectionState
namespace WindowsApplication1
{
public class DBHelp
{ public static OracleConnection conn = new OracleConnection("Data Source=wzinner;Persist Security Info=True;User ID=common;password=common;Unicode=True");
//conn.StateChange += new StateChangeEventHandler(OnStateChanged);
//conn.ConnectionString = ;
//查询
public static OracleDataReader ExcuterRead(string sql)
{
//if (conn.State == ConnectionState.Closed)
conn.Open();
OracleCommand command = new OracleCommand(sql, conn);
OracleDataReader sdr = command.ExecuteReader(); return sdr;
}
//修改
public static int ExcutSslet(string mysql)
{
conn.Open();
OracleCommand command = new OracleCommand(mysql,conn); int reulet = Convert.ToInt32(command.ExecuteNonQuery());
conn.Close(); return reulet;
}
}
}当运行完 int reulet = Convert.ToInt32(command.ExecuteNonQuery()); 就会跳到修改的异常那..求高手```` 谢谢``
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OracleClient;
using System.Data.OleDb;
using System.Data.Odbc;namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{ if (textBox1.Text == "")
{
MessageBox.Show("请输入查询条件!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return;
} int id = Convert.ToInt32(textBox1.Text);
string sql = string.Format("select em_house_t.p_priv_flarea,em_house_t.p_co_flarea,em_house_t.p_ratial,em_house_t.p_flarea,em_house_t.FLAREA,em_house_t.PRIV_FLAREA,em_house_t.RATIAL,em_house_t.CO_FLAREA,em_house_t.FLAREA,em_location_t.LOCATION_NAME from em_house_t,em_location_t,EM_FLAT_LOC_T" +
" where em_house_t.HOUSE_ID= em_flat_loc_t.HOUSE_ID and" +
" em_location_t.LOCATION_ID=em_flat_loc_t.LOCATION_ID and em_house_t.HOUSE_ID='{0}'", id);
try
{
OracleDataReader dReader = DBHelp.ExcuterRead(sql);
if (dReader.Read())
{ this.textBox2.Text = dReader["p_priv_flarea"].ToString();
this.textBox3.Text = dReader["p_co_flarea"].ToString();
this.textBox4.Text = dReader["p_ratial"].ToString();
this.textBox5.Text = dReader["p_flarea"].ToString();
this.textBox6.Text = dReader["PRIV_FLAREA"].ToString();
this.textBox7.Text = dReader["LOCATION_NAME"].ToString();
this.textBox8.Text = dReader["RATIAL"].ToString();
this.textBox9.Text = dReader["CO_FLAREA"].ToString();
this.textBox10.Text = dReader["FLAREA"].ToString();
}
else
{
MessageBox.Show("没有你要查找的数据", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
} dReader.Close();
}
catch (Exception ex)
{ MessageBox.Show(ex.Message);
}
finally
{
DBHelp.conn.Close();
}
}
//修改 测试id 2289343
private void button2_Click(object sender, EventArgs e)
{
int id = Convert.ToInt32(textBox1.Text); string sql = string.Format("update em_house_t set PRIV_FLAREA='{0}',RATIAL='{1}',CO_FLAREA='{2}',FLAREA='{3}',p_priv_flarea='{4}',p_co_flarea='{5}',p_ratial='{6}',p_flarea='{7}' where house_id='{8}'", textBox6.Text, textBox8.Text, textBox9.Text, textBox10.Text,textBox2.Text,textBox3.Text,textBox4.Text,textBox5.Text, id);
try
{
//OracleDataReader dReader = DBHelp.ExcuterRead(sql); int reulet =Int32.Parse( DBHelp.ExcutSslet(sql).ToString());
if (reulet != 1)
{
MessageBox.Show("修改失败!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("修改成功!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (Exception ee)
{
MessageBox.Show(ee.Message);
}
} }
}
DBHelp 类using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OracleClient;
using System.Windows.Forms;
using System.Data;
//System.Data.ConnectionState
namespace WindowsApplication1
{
public class DBHelp
{ public static OracleConnection conn = new OracleConnection("Data Source=wzinner;Persist Security Info=True;User ID=common;password=common;Unicode=True");
//conn.StateChange += new StateChangeEventHandler(OnStateChanged);
//conn.ConnectionString = ;
//查询
public static OracleDataReader ExcuterRead(string sql)
{
//if (conn.State == ConnectionState.Closed)
conn.Open();
OracleCommand command = new OracleCommand(sql, conn);
OracleDataReader sdr = command.ExecuteReader(); return sdr;
}
//修改
public static int ExcutSslet(string mysql)
{
conn.Open();
OracleCommand command = new OracleCommand(mysql,conn); int reulet = Convert.ToInt32(command.ExecuteNonQuery());
conn.Close(); return reulet;
}
}
}当运行完 int reulet = Convert.ToInt32(command.ExecuteNonQuery()); 就会跳到修改的异常那..求高手```` 谢谢``
int id = Convert.ToInt32(textBox1.Text); 是这句吗?
不行,一样的有问题` 说不能转换``
你把这错执行完后,把拼接过后的sql的值发出来,感觉 有点问题,可能主要问题就在这里了
是这段update em_house_t set PRIV_FLAREA='732.53',RATIAL='',CO_FLAREA='176.24',FLAREA='908.11',p_priv_flarea='',p_co_flarea='',p_ratial='',p_flarea='' where house_id='2289343'
string sql = string.Format("update em_house_t set PRIV_FLAREA='{0}',RATIAL='{1}',CO_FLAREA='{2}',FLAREA='{3}'这里,后面的那个地方是个中文的逗号,下次注意就是了,记得要结一下帖子