有关如何将MS Access数据库连接到C程序的问题 [英] Question on how to connect MS access database to C program

查看:86
本文介绍了有关如何将MS Access数据库连接到C程序的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我只想问一下.如何将MS Access数据库连接到C程序.请参见下面的代码:

Hello, I just only want to ask.How to connect MS access database to a C program.See the code below:

#include<stdio.h>
char firstname[20], middlename, lastname[20];
main()
{
   clrscr();
   printf("Enter your First Name: ");scanf("%s",&firstname);
   printf("Enter your Middle Name: ");scanf("%c",&middlename);
   printf("Enter your Last Name: ");scanf("%s",&lastname);
   getch();
}



这就是我想要做的,例如,我有一个名为myname.mdb的数据库文件,并且在该数据库中有三个字段:fname,mname和lname.

我希望将firstname的值传递给fname,将Middlename的值传递给mname,并且将lastname的值传递给lname



This is what I want to do for example I have a database file named myname.mdb and in that database there are three fields: fname, mname and lname.

I want the value of firstname pass to fname, middlename pass to mname, and lastname pass to lname

推荐答案

这里是一篇介绍基本内容的文章:使用本机C或C ++开发Access 2007解决方案 [
Here''s one article explaining basic things: Developing Access 2007 Solutions with Native C or C++[^]


第一件事:甚至都不要尝试!
First thing to do: don''t even try like that!
char firstname[20], middlename, lastname[20];
main()
{
clrscr();
printf("Enter your First Name: ");scanf("%s",&firstname);
printf("Enter your Middle Name: ");scanf("%c",&middlename);
printf("Enter your Last Name: ");scanf("%s",&lastname);
getch();

<code>中间名是单个字符:即除任何空字符串外,它不能容纳从scanf返回的任何内容!
&firstname是指向char的指针. scanf需要一个指向char的指针. &lastname
一样
相反,请尝试以下操作:

<code>middlename is a single char: i.e. it cannot hold anything returned from scanf except any empty string!
&firstname is a pointer to a pointer to a char. scanf wants a pointer to a char. The same for &lastname

Instead, try this:

#include<stdio.h>
char firstname[20], middlename[20], lastname[20];
main()
   {
   clrscr();
   printf("Enter your First Name: ");scanf("%s",firstname);
   printf("Enter your Middle Name: ");scanf("%c",middlename);
   printf("Enter your Last Name: ");scanf("%s",lastname);
   getch();
   }


这篇关于有关如何将MS Access数据库连接到C程序的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆