已连接上access数据表,在list control(变量名m_Grid)中显示其数据。现在要给数据表添加字段,字段名通过edit control(变量名m_FieldName)输入。
(用excute执行sql语句来解决)。并且list control能显示新添加的字段。下面是我得代码。
UpdateData(TRUE);
if(m_FieldName.IsEmpty())
{
MessageBox("请输入要添加的字段名!");
return;
}
OnInitADOConn();
CString str;
str=m_FieldName;
bstr_t bstrSQL;
bstrSQL="alter table employees add str int "; //这里需要修改
m_pCommand.CreateInstance (_uuidof(Command));
try
{
m_pCommand->ActiveConnection = m_pConnection;
m_pCommand->CommandText = (_bstr_t)bstrSQL;
m_pCommand->Execute(NULL, NULL, adCmdText);
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
m_Grid.InsertColumn(4,str,LVCFMT_LEFT,110,3);//这里需要修改我现在的问题是,sql语句不正确,数据库不能添加编辑框中输入的字段,请教各位此处怎么修改?谢谢了
另外list框的更新显示是不是有更简单有效的方法。
我刚接触vc,不通。还望各位不吝指教!不胜感谢。
(用excute执行sql语句来解决)。并且list control能显示新添加的字段。下面是我得代码。
UpdateData(TRUE);
if(m_FieldName.IsEmpty())
{
MessageBox("请输入要添加的字段名!");
return;
}
OnInitADOConn();
CString str;
str=m_FieldName;
bstr_t bstrSQL;
bstrSQL="alter table employees add str int "; //这里需要修改
m_pCommand.CreateInstance (_uuidof(Command));
try
{
m_pCommand->ActiveConnection = m_pConnection;
m_pCommand->CommandText = (_bstr_t)bstrSQL;
m_pCommand->Execute(NULL, NULL, adCmdText);
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
m_Grid.InsertColumn(4,str,LVCFMT_LEFT,110,3);//这里需要修改我现在的问题是,sql语句不正确,数据库不能添加编辑框中输入的字段,请教各位此处怎么修改?谢谢了
另外list框的更新显示是不是有更简单有效的方法。
我刚接触vc,不通。还望各位不吝指教!不胜感谢。
解决方案 »
- 属性页多行显示
- 兄弟们,来帮个忙咯,关于CHttpFile* 的QueryInfo 的问题
- 【原创&交流】对话框上全图显示图像的两种做法
- 界面小问题,大伤脑筋啊!!!求助。。。
- 怎么用给ActiveX添加一个带参数方法怎么用VB写它的调试代码?
- COM传递图像数据!高分急救!!!!
- CTypedPtrArray不是MFC里的一个模板类吗?为什么会出错?**********
- 窗口句柄
- MDI中,怎样在MyAppDoc()中获得MyAppView()里的pDC?????
- ★★★☆☆☆ JPG 文件的开始处 是这样的吗?
- 在OnEraseBkgnd上设置对话框背景图并做了透明处理,切换窗口出现问题?
- operator void* 是什么意思?
不建议使用COM对数据库表进行字段修改
SQL 语句分为 DDL 和 DCL。
你这个语句属于 DDL。看下边这篇文章:
How to use common Data Definition Language (DDL) SQL statements for the Jet database engine
http://support.microsoft.com/?scid=kb;en-us;180841&x=7&y=8
CString strSQL;
strSQL.Format("alter table employees add %s int",m_FieldName);
...
m_pCommand->CommandText = (_bstr_t)strSQL;