下面的代码写错了 [英] The code write below has error

查看:73
本文介绍了下面的代码写错了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码,但它只输入其他部分。如果没有输入部分,我无法收到错误....









con.Open();

int a1;

a1 = int.Parse(textBox3.Text);

string r2 = textBox2.Text;

string q3 = textBox1.Text;

SqlCommand cmd = new SqlCommand(select * from ledger where year ='+ r2 +'and purticulars ='+ q3 +',con);

SqlDataAdapter da = new SqlDataAdapter(cmd );

DataTable dt = new DataTable();

da.Fill(dt);

if(dt.Rows.Count> 0)

{

int ti = Convert.ToInt32(dt.Rows [0] [credit]。ToString());

int q = ti - a1;



SqlCommand cmd3 = new SqlCommand(update ledger set credit ='+ q +其中purticulars ='+ q3 +'和year ='+ r2 +',con);

cmd3.ExecuteNonQuery();



}

else

{

MessageBox.Show(error);

}

con.Close();



我尝试过:



con.Open();

int a1;

a1 = int.Parse(textBox3.Text);

string r2 = textBox2.Text;

string q3 = textBox1.Text;

SqlCommand cmd = new SqlCommand(select * from ledger where year ='+ r2 +'和purticulars ='+ q3 +',con);

SqlDataAdapter da = new SqlDataAdapter(cmd);

DataTable dt = new DataTable() ;

da.Fill(dt);

if(dt.Rows.Count> 0)

{

int ti = Convert.ToInt32(dt.Rows [0] [credit]。ToString());

int q = ti - a1;



SqlCommand cmd3 = new SqlCommand(update ledger set credit ='+ q +'where purticulars ='+ q3 +'和年='+ r2 +',con);

cmd3.ExecuteNonQuery();



}

else

{

MessageBox.Show(error);

}

con.Close();



///它只能用于其他部分

this is my code, but it enter else part only.it didn't enter to if part ,i couldn't get the error....




con.Open();
int a1;
a1 = int.Parse(textBox3.Text);
string r2 = textBox2.Text;
string q3 = textBox1.Text;
SqlCommand cmd = new SqlCommand("select * from ledger where year ='" + r2 + "'and purticulars ='" + q3 + "'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
int ti = Convert.ToInt32(dt.Rows[0]["credit"].ToString());
int q = ti - a1;

SqlCommand cmd3 = new SqlCommand("update ledger set credit ='" + q + "' where purticulars='" + q3 + "' and year='" + r2 + "'", con);
cmd3.ExecuteNonQuery();

}
else
{
MessageBox.Show("error");
}
con.Close();

What I have tried:

con.Open();
int a1;
a1 = int.Parse(textBox3.Text);
string r2 = textBox2.Text;
string q3 = textBox1.Text;
SqlCommand cmd = new SqlCommand("select * from ledger where year ='" + r2 + "'and purticulars ='" + q3 + "'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
int ti = Convert.ToInt32(dt.Rows[0]["credit"].ToString());
int q = ti - a1;

SqlCommand cmd3 = new SqlCommand("update ledger set credit ='" + q + "' where purticulars='" + q3 + "' and year='" + r2 + "'", con);
cmd3.ExecuteNonQuery();

}
else
{
MessageBox.Show("error");
}
con.Close();

///it only work the else part

推荐答案

OP发表:
引用:

tankuu非常先生...我得到了你的帮助

tankuu very much sir...i got it with ur help



回答仅从未答复的队列中删除。


Answered only to remove from unanswered queue.


这篇关于下面的代码写错了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆