急!C#问题

[复制链接]
查看11 | 回复4 | 2010-12-6 09:53:11 | 显示全部楼层 |阅读模式
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 RenterManage
{

public partial class Renter : Form

{

public Renter()

{

InitializeComponent();

this.sqlConnection1 = new SqlConnection(database.dbconnection.conncetion);

this.sqlCommand1 = new SqlCommand();

this.sqlCommand1.Connection = this.sqlConnection1;

this.add = false;

rentermanage = new RenterManage();

}

private void Renter_Load(object sender, EventArgs e)

{

this.strSql = "Select RenterName 姓名,Contact 联系方式,ContractID 合同编号," + "RenterRental 出租人租金,Remark 备注, RenterID 出租人编号" + "from Renter";

this.FillDataGrid(strSql);

}

private void FillDataGrid(string sql)

{

if (this.sqlConnection1.State == ConnectionState.Closed)

this.sqlConnection1.Open();

Console.WriteLine(sql);

SqlDataAdapter adapter = new SqlDataAdapter(sql,sqlConnection1);

ds = new DataSet("t_renter");

adapter.Fill(ds,"t_renter");

this.dataGrid1.SetDataBinding(ds,"t_renter");

}

}
}调试会出来异常,Renter附近出现语法错误

回复

使用道具 举报

千问 | 2010-12-6 09:53:11 | 显示全部楼层
既然人家提示是语法错误,那你就要检查你的sql语句,一定是哪个地方写错了,你可以把你的sql语句复制到sql中调试。你的sql显然不对,至少 from前面没有空格。
回复

使用道具 举报

千问 | 2010-12-6 09:53:11 | 显示全部楼层
this.strSql = "Select RenterName 姓名,Contact 联系方式,ContractID 合同编号," + "RenterRental 出租人租金,Remark 备注, RenterID 出租人编号" + "from Renter"from前面加上空格。" from Renter"
回复

使用道具 举报

千问 | 2010-12-6 09:53:11 | 显示全部楼层
this.strSql = "Select (RenterName 姓名,Contact 联系方式,ContractID 合同编号," + "RenterRental 出租人租金,Remark 备注, RenterID 出租人编号)" + " from Renter";
回复

使用道具 举报

千问 | 2010-12-6 09:53:11 | 显示全部楼层
建议你去CSDN论坛里去问。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行