How insert data in Database MS access Through User Defined GUI
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
can any one tell how to insert data in database through GUI like making some Edit text boxes and Button in GUI and When User click the All Data Is saved in Database please tell me For MS access Database i do this in Under Button
conn = database('MMU2', 'sherykhan', 'shery')
colnames = {'ID','Country'};
edata={user_string1,user_string2}
get(conn, 'AutoCommit')
insert(conn, 'ac_iris', colnames, edata)
close(curs)
close(conn)
and this in two Edit text boxes
user_string2= get(hObject,'String');
user_string1=get(hobject,string);
please tell me the Way i need that when User Will Enter some Data in Edit boxes the Data is Submitted to Database MMU like . i am usin Matlab R2010a Version
채택된 답변
Geoff Hayes
2015년 3월 28일
Shery - use GUIDE to create your GUI with two edit boxes (named edit1 and edit2) and one push button. Then, in the callback to your push button, you can reference the edit boxes using their handles. Something like
function pushbutton1_Callback(hObject, eventdata, handles)
user_string1 = get(handles.edit1,'String');
user_string2 = get(handles.edit2,'String');
then continue with your connection to the MS Access database. See here for details on how to connect with ODBC.
댓글 수: 8
shery khan
2015년 3월 28일
편집: Geoff Hayes
2015년 3월 29일
sir thanks sir for your reply but which you have Refer i can read it and do it i am using R2010a Version Kindly Guide Me What Error in this Code is
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
s=oledbcnstr('Access',[],'MMU2.mdb');
cn=oledbcn(s);
cn=database('Access','','');
ID=get(handles.ID,'string');
country=get(handles.edit2,'string');
Nationality=get(handles.edit3,'string');
Region=get(handles.edit4,'string');
Age=get(handles.edit5,'string');
gender=get(handles.edit6,'string');
Enviroment=get(handles.edit7,'string');
data={ID country Nationality Region Age gender Enviornment}
col={'ID', 'Country' , 'Nationality', 'Region', 'Age', 'gender', 'Enviroment'}
insert(cn,'ac_iris',col,data);
msgbox('record Saved Sucessfully?','save','warn');
close(cn);
all the Steps i follow but Guide me How I can Do this User Will Enter Data in GUI and the Data Will Save or Inserted to Database MS access File
Shery - if you are observing or an encountering an error with the above code, then please post the error. Or, better yet, step through the code using the debugger to see what is happening. I can't run your code since I don't have access to your database and so cannot tell you what is wrong though I suspect there may be a problem with the line
data={ID country Nationality Region Age gender Enviornment}
since Enviornment is different from Enviroment declared on the previous line.
shery khan
2015년 3월 29일
편집: Geoff Hayes
2015년 3월 29일
Look I have Created Following Fields in GUI ID, Nationality ,Region', 'Age', 'gender', 'Enviroment using Eight Edit boxes and One Button Now Database is on Path With Name MMU2 Which has a Table named ac_iris which contain also these Fields which i have created in GUI now under Editboxes i cannot write any code just in Button i write Above Code but Error Will be on this line s=oledbcnstr('Access',[],'MMU2.mdb'); similarly Error is
% ??? Undefined function or method 'oledbcnstr' for input
arguments of type 'char'.
Error in ==> intialpage>pushbutton1_Callback at 219
s=oledbcnstr('Access',[],'MMU2.mdb');
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> intialpage at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==>
@(hObject,eventdata)intialpage('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
shery khan
2015년 3월 29일
편집: Geoff Hayes
2015년 3월 29일
i can tell you that when i enter data through Command window using this Code below the Row of Database will be Updated but when using GUI it will Give Error i am very thankfull to you that you can Reply me
user_string2=5
user_string1=pakistan
conn = database('MMU2', 'sherykhan', 'shery')
colnames = {'ID','Country'};
edata={user_string1,user_string2}
get(conn, 'AutoCommit')
insert(conn, 'ac_iris', colnames, edata)
close(curs)
close(conn)
Geoff Hayes
2015년 3월 29일
편집: Geoff Hayes
2015년 3월 29일
Have you downloaded the function oledbcnstr from the File Exchange and placed it in the MATLAB search path? In the Command Window, type
which -all oledbcnstr
to see where this file is. If you observe the message
'oledbcnstr' not found.
then download the file.
In the code in your previous comment, you don't even mention the file oledbcnstr so why does your GUI code use something different? As for the above working in the Command Window and not through the GUI, have you stepped through the GUI code - using the debugger - to see how your data cell array compares with edata?
shery khan
2015년 3월 29일
편집: shery khan
2015년 3월 29일
Now Error in oledbcn.m
if true
??? Error using ==> oledbcn at 60
Could not create connection. See troubleshooting
above.
Error in ==> intialpage>pushbutton1_Callback at 221 cn=oledbcn(s);
Error in ==> gui_mainfcn at 96 feval(varargin{:});
Error in ==> intialpage at 42 gui_mainfcn(gui_State, varargin{:});
Error in ==> @(hObject,eventdata)intialpage('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
60 error('Could not create connection. See troubleshooting above.') K>> end
thanks sir your kind help will so Good now tell me Error in insert .m as you previously say that i can add files oledbscntr and other files in my path without editing or change them but now error so please kindly tell me what to do now Thank you So Much sir your Guide lines are so Good for me
Geoff Hayes
2015년 3월 29일
편집: Geoff Hayes
2015년 3월 29일
Unfortunately, shery, the error information that you provided is not enough to determine what the problem is. Have you changed your code, and if so, to what? oledbcn appears to be a function that you have not referenced before. How are you calling this function? What are the inputs?
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Database Toolbox에 대해 자세히 알아보기
제품
태그
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
