首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

出现一下异常:“DGGL.SQL.strSQL”是“字段”,但此处被当做“方法”来使用 请各位帮忙解决下

2012-05-05 
出现一下错误:“DGGL.SQL.strSQL”是“字段”,但此处被当做“方法”来使用 请各位大虾帮忙解决下。using Systemu

出现一下错误:“DGGL.SQL.strSQL”是“字段”,但此处被当做“方法”来使用 请各位大虾帮忙解决下。
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 DGGL
{
  public partial class chakandaigoubiao : Form
  {
  string connectString;
  DataTable dt;
  SqlParameter[] paras = new SqlParameter[4];
  int pageCount, pageSize, pageIndex, recordCount;
  bool error;

  public chakandaigoubiao()
  {
  InitializeComponent();
  }

  private void button3_Click(object sender, EventArgs e)
  {
  this.Close();
  }

  private void chakandaigoubiao_Load(object sender, EventArgs e)
  {
  pageSize = 50;
  pageIndex = 0;
  [color=#FF0000] connectString = SQL.strSQL(); //错误发生点。[/color]

  if (!backgroundWorker1.IsBusy)
  backgroundWorker1.RunWorkerAsync();
  }

  private void button4_Click(object sender, EventArgs e)
  {

  if (pageIndex == 0)
  return;

  pageIndex = 0;

  if (!backgroundWorker1.IsBusy)
  backgroundWorker1.RunWorkerAsync();
  }

  private void button5_Click(object sender, EventArgs e)
  {
  if (pageIndex < 1)
  return;

  pageIndex--;
  if (!backgroundWorker1.IsBusy)
  backgroundWorker1.RunWorkerAsync();
  }

  private void getPage(int pIndex)
  {
  dt = new DataTable();
  using (SqlConnection con = new SqlConnection(connectString))
  {
  SqlCommand sc = new SqlCommand();
  sc.Connection = con;
  sc.CommandType = CommandType.StoredProcedure;
  sc.CommandText = "Pages";

  paras[0] = new SqlParameter("@PageIndex", SqlDbType.Int);
  paras[0].Value = pIndex;
  paras[1] = new SqlParameter("@PageSize", SqlDbType.Int);
  paras[1].Value = pageSize;
  paras[2] = new SqlParameter("@RecordCount", SqlDbType.Int);
  paras[2].Direction = ParameterDirection.Output;
  paras[3] = new SqlParameter("@PageCount", SqlDbType.Int);
  paras[3].Direction = ParameterDirection.Output;

  for (int i = 0; i < paras.Length; i++)
  sc.Parameters.Add(paras[i]);

  SqlDataAdapter da = new SqlDataAdapter(sc);
  da.Fill(dt);
  }
  }

  private void button6_Click(object sender, EventArgs e)
  {
  if (pageIndex == pageCount - 1)
  return;

  pageIndex++;

  if (!backgroundWorker1.IsBusy)
  backgroundWorker1.RunWorkerAsync();
  }

  private void button7_Click(object sender, EventArgs e)
  {
  if (pageIndex == pageCount - 1)
  return;

  pageIndex = pageCount - 1;


  if (!backgroundWorker1.IsBusy)
  backgroundWorker1.RunWorkerAsync();
  }

  private void textBox1_KeyDown(object sender, KeyEventArgs e)
  {
  if (e.KeyCode == Keys.Enter)
  {
  int pIndex;

  pIndex = Convert.ToInt32(textBox1.Text);

  if (pIndex >= pageCount || pIndex < 0)
  {
  MessageBox.Show("范围不对");
  textBox1.Text = "";
  }
  else
  {
  pageIndex = pIndex;
  if (!backgroundWorker1.IsBusy)
  backgroundWorker1.RunWorkerAsync();
  }
  }
  }

  private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
  {
  try
  {
  getPage(pageIndex);
  error = false;
  }
  catch (Exception ex)
  {
  MessageBox.Show(ex.ToString());
  error = true;
  }
  }

  private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
  {
  if (!error)
  {
  recordCount = Convert.ToInt32(paras[2].Value);
  pageCount = Convert.ToInt32(paras[3].Value);

  label1.Text = pageCount + "页 " + recordCount + "条记录";
  dataGridView1.DataSource = dt;
  textBox1.Text = pageIndex.ToString();
  }
  }

   
  }
}


####:出现一下错误:“DGGL.SQL.strSQL”是“字段”,但此处被当做“方法”来使用
请各位大虾帮忙解决下。

[解决办法]
混淆字段和方法了你

connectString = SQL.strSQL(); //你的这个是方法

connectString = SQL.strSQL; //这个才是字段(属性)

热点排行