请帮忙!本人不熟悉VC,但要用到一点东西,需要连接数据库,不知道怎么连接?急!急!急! 用VC连接SQL SERVER 2000数据库: 1。要用ADO字符串连接,所有参数要从ini文件中读取。(怎样写ini文件或读ini文件) 2。怎样将记录写入数据库。 3。最好给一个完整的示例。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 其实.ini文件也是纯文本文件,用CFile类就可以了,下面是我以前初始化表格字段大小写的一断,虽然烦了点,将就一下吧;-)//读文件 //以下是初始化datagrid的width CFile file; BYTE temp[400]; memset(temp,0,400); int s1=0,s2=0,value; CString str,tempstr,str1,width; file.Open ("grids.ini",CFile::modeReadWrite|CFile::modeCreate|CFile::modeNoTruncate); file.Read (temp,400); tempstr.Format ("%s",temp); for(int i=0;i<8;i++) { str.Format ("%d",i); str1.Format ("[%d]",i); s1=tempstr.Find(str1); s1=tempstr.Find("=",s1); s2=tempstr.Find (";",s1); width=tempstr.Mid (s1+1,s2-(s1+1)); value=atoi(width); m_datagrid1.GetColumns ().GetItem (_variant_t(str)).SetWidth (value); } file.Close ();//写文件 CFile file; BYTE temp[400]; char cha[400]; memset(cha,0,400); memset(temp,0,400); float f; int s1=0,s2=0; CString str,tempstr; str.Format ("%d",ColIndex); file.Open ("grids.ini",CFile::modeReadWrite|CFile::modeCreate|CFile::modeNoTruncate); file.Read (temp,400); f=m_datagrid1.GetColumns ().GetItem (_variant_t(str)).GetWidth (); tempstr.Format ("%s",temp); str.Format ("[%d]",ColIndex); s1=tempstr.Find(str); s1=tempstr.Find("=",s1); s2=tempstr.Find (";",s1); tempstr.Delete (s1+1,s2-s1-1); str.Format ("%d",int(f)); tempstr.Insert (s1+1,str); strcpy(cha,tempstr); memcpy(temp,cha,400); file.SeekToBegin (); file.Write (temp,400); file.Close (); //写入数据库我是用C_Recordset类的Update函数 long ind[2]; C_Recordset Recordsetbook= m_ado1.GetRecordset (); C_Recordset Recordsetone= m_ado2.GetRecordset (); COleSafeArray vaFieldlist,vaValuelist; vaFieldlist.CreateOneDim (VT_VARIANT,1); vaValuelist.CreateOneDim (VT_VARIANT,1); ind[0]=0; if(str!="") { vaFieldlist.PutElement(ind,&(_variant_t("剩下册数"))); vaValuelist.PutElement(ind,&(_variant_t(str))); Recordsetbook.Update (vaFieldlist,vaValuelist); } vaFieldlist.PutElement(ind,&(_variant_t("备注"))); vaValuelist.PutElement(ind,&(_variant_t(m_more))); Recordsetone.Update (vaFieldlist,vaValuelist); vaFieldlist.PutElement(ind,&(_variant_t("目前位置"))); vaValuelist.PutElement(ind,&(_variant_t(m_position))); Recordsetbook.Update (vaFieldlist,vaValuelist);你试试吧!或许能用 if(m_pADOSet->State) m_pADOSet->Close(); zxs3543() ( )说得好,我就是按你的方法搞定的,整整一天了。 急求:有什么方法可以把同一变量名根据不同条件定义成不同的数据类型 如何用VC++来生成olb(对象类型库)文件的? 不知该不该用多线程 小弟不才,学了VC一小段时间,终于写了个小东西,请大家指点指点 **求教,在一个程序中,调用其他的两个程序** 再次求代码, VC, 只用API调用而不是MFC或ATL来实现一个最简单的, 不用任何其它功能的间窗口浏览器代码, 愿出300分(试了能用就给) 求助!编译不能通过~? 请教:关于XML 如何用程序控制IE打印设置,help! 天同证券招高级程序员数名。 请您指点。100分 (急~~) 流量方面的问题,大家帮忙看看!!
//读文件
//以下是初始化datagrid的width
CFile file;
BYTE temp[400];
memset(temp,0,400);
int s1=0,s2=0,value;
CString str,tempstr,str1,width;
file.Open ("grids.ini",CFile::modeReadWrite|CFile::modeCreate|CFile::modeNoTruncate);
file.Read (temp,400);
tempstr.Format ("%s",temp); for(int i=0;i<8;i++)
{
str.Format ("%d",i);
str1.Format ("[%d]",i);
s1=tempstr.Find(str1);
s1=tempstr.Find("=",s1);
s2=tempstr.Find (";",s1);
width=tempstr.Mid (s1+1,s2-(s1+1));
value=atoi(width);
m_datagrid1.GetColumns ().GetItem (_variant_t(str)).SetWidth (value); }
file.Close ();
//写文件 CFile file;
BYTE temp[400];
char cha[400];
memset(cha,0,400);
memset(temp,0,400);
float f;
int s1=0,s2=0;
CString str,tempstr;
str.Format ("%d",ColIndex);
file.Open ("grids.ini",CFile::modeReadWrite|CFile::modeCreate|CFile::modeNoTruncate);
file.Read (temp,400);
f=m_datagrid1.GetColumns ().GetItem (_variant_t(str)).GetWidth (); tempstr.Format ("%s",temp);
str.Format ("[%d]",ColIndex);
s1=tempstr.Find(str);
s1=tempstr.Find("=",s1);
s2=tempstr.Find (";",s1);
tempstr.Delete (s1+1,s2-s1-1);
str.Format ("%d",int(f));
tempstr.Insert (s1+1,str); strcpy(cha,tempstr);
memcpy(temp,cha,400);
file.SeekToBegin ();
file.Write (temp,400);
file.Close (); //写入数据库我是用C_Recordset类的Update函数 long ind[2];
C_Recordset Recordsetbook= m_ado1.GetRecordset ();
C_Recordset Recordsetone= m_ado2.GetRecordset ();
COleSafeArray vaFieldlist,vaValuelist;
vaFieldlist.CreateOneDim (VT_VARIANT,1);
vaValuelist.CreateOneDim (VT_VARIANT,1);
ind[0]=0;
if(str!="")
{
vaFieldlist.PutElement(ind,&(_variant_t("剩下册数")));
vaValuelist.PutElement(ind,&(_variant_t(str)));
Recordsetbook.Update (vaFieldlist,vaValuelist);
}
vaFieldlist.PutElement(ind,&(_variant_t("备注")));
vaValuelist.PutElement(ind,&(_variant_t(m_more)));
Recordsetone.Update (vaFieldlist,vaValuelist); vaFieldlist.PutElement(ind,&(_variant_t("目前位置")));
vaValuelist.PutElement(ind,&(_variant_t(m_position)));
Recordsetbook.Update (vaFieldlist,vaValuelist);
你试试吧!或许能用