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
採用された回答
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!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
