在一个文本框中输入的数据怎么传到ado data comtrol控件,即传给Cammand Text(SQL)。我是在文本框中输入的数据,进行查询,利用以下查询语句到了想要查询的结果,并将查询结果在data grid控件显示出来。SQL我是这样写的:select * from formula,formula_message where formula.file_id= 'file_id' and formula.file_id=formula_message.file_id order by material_classification desc
红色的file_id是我在输入框得到的变量值。(这个查询语句我已经在查询分析器里通过了有结果)为什么data grid控件没能显示出结果。(两控件我已经绑定了,没错误)
红色的file_id是我在输入框得到的变量值。(这个查询语句我已经在查询分析器里通过了有结果)为什么data grid控件没能显示出结果。(两控件我已经绑定了,没错误)
//#include "stdafx.h"
#include "management_system.h"
#include "QueryFormulaDlg.h"
#include "COMDEF.H"
#include "column.h"
#include "columns.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CQueryFormulaDlg dialog
CQueryFormulaDlg::CQueryFormulaDlg(CWnd* pParent /*=NULL*/)
: CDialog(CQueryFormulaDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CQueryFormulaDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CQueryFormulaDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CQueryFormulaDlg)
DDX_Control(pDX, IDC_ADODC1, m_Adodc);
DDX_Control(pDX, IDC_DATAGRID1, m_Datagrid);
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CQueryFormulaDlg, CDialog)
//{{AFX_MSG_MAP(CQueryFormulaDlg)
ON_BN_CLICKED(IDOK, OnQuery)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CQueryFormulaDlg message handlersBOOL CQueryFormulaDlg::OnInitDialog()
{
CDialog::OnInitDialog();
RefreshData();
return TRUE;
}void CQueryFormulaDlg::RefreshData()
{
UpdateData(TRUE);
// 设置Select语句
CString cSource = "select * from formula,formula_message where formula.file_id= 'file_id' and formula.file_id=formula_message.file_id order by material_classification desc";
//刷新ADO Data控件的记录源
m_Adodc.SetRecordSource(cSource);
m_Adodc.Refresh(); /* _variant_t vIndex;
vIndex = long(0);
m_Datagrid.GetColumns().GetItem(vIndex).SetWidth(150);
vIndex = long(1);
m_Datagrid.GetColumns().GetItem(vIndex).SetWidth(80);
vIndex = long(2);
m_Datagrid.GetColumns().GetItem(vIndex).SetWidth(230);
*/
return;
}void CQueryFormulaDlg::OnQuery()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
GetDlgItemText(IDC_File,file_id); // GetDlgItemInt(IDC_Max_Weight,max_weight); if(file_id=="")
{
MessageBox("请输入文件编号!","信息提示", MB_ICONINFORMATION);
GetDlgItem(IDC_File)->SetFocus();
return;
}
}
是这样的......看看