matlab gui修改名称后错误,matlab gui增删改操作出错怎么办??

stellari 发表于 2013-5-2 01:51 bbd016eb636182ff59f287f6e5567aa8.gif

看起来是insert这个函数的调用方法有问题。你需要查询一下这个函数的使用方法,并保证给入的每个参数的值于 ...

function insert(connect,tableName,fieldNames,data)

%INSERT Export MATLAB cell array data into database table.

%   INSERT(CONNECT,TABLENAME,FIELDNAMES,DATA).

%   CONNECT is a database connection handle structure, FIELDNAMES

%   is a string array of database column names, TABLENAME is the

%   database table, DATA is a MATLAB cell array.    For improved

%   write performance and support for additional data types, use the

%   function FASTINSERT.

%

%

%   Example:

%

%

%   The following INSERT command inserts the contents of

%   the cell array in to the database table yearlySales

%   for the columns defined in the cell array colNames.

%

%

%   insert(conn,'yearlySales',colNames,monthlyTotals);

%

%   where

%

%   The cell array colNames contains the value:

%

%   colNames = {'salesTotal'};

%

%   monthlyTotals is a cell array containing the data to be

%   inserted into the database table yearlySales

%

%   insert(conn,'yearlySales',colNames,monthlyTotals);

%

%

%   See also FASTINSERT, UPDATE.

%   Copyright 1984-2005 The MathWorks, Inc.

%   $Revision: 1.24.4.9 $        $Date: 2007/07/03 20:42:00 $%

% Check for valid connection

if isa(connect.Handle,'double')

error('database:database:invalidConnection','Invalid connection.')

end

% Create start of the SQL insert statement

% First get number of columns in the cell array

%Get dimensions of data

switch class(data)

case {'cell','double','logical'}

[numberOfRows,cols] = size(data);        %data dimensions

case 'struct'

sflds = fieldnames(data);

fchk = setxor(sflds,fieldNames);

if ~isempty(fchk)

error('database:database:writeMismatch','Structure fields and insert fields do not match.')

end

eval(['numberOfRows = size(data.' sflds{1} ',1);'])

cols = length(sflds);

otherwise

error('database:database:invalidWriteDataType','Input data must be a cell array, matrix, or structure')

end

% Case 1 all fields are being written to in the target database table.

insertField = '';

% Create the field name string for the INSERT statement .. this defines the

% fields in the database table that will be receive data.

for i=1:cols,

if ( i == cols),

insertField = [ insertField fieldNames{i} ];

else

insertField = [ insertField fieldNames{i} ',' ];

end

end

% Create the head of the SQL statement

startOfString = [ 'INSERT INTO '  tableName ' (' insertField ') ' 'VALUES ( ' ];

% Get NULL string and number preferences

prefs = setdbprefs;

nsw = prefs.NullStringWrite;

nnw = str2num(prefs.NullNumberWrite);

% Add the data for all the columns in the cell array.

for i = 1:numberOfRows,

dataString ='';

for j = 1:cols,

switch class(data)

case {'cell','double','uint8','uint16','uint32','uint64','int8','int16','int32','int64','single'}

try   %Index as cell array, or matrix, if not cell array

tmp = data{i,j};

catch

tmp = data(i,j);

end

case 'struct'

try

tmp = data.(sflds{j}){i};

catch

tmp = data.(sflds{j})(i,:);

end

end

if isnumeric(tmp) || isa(tmp,'logical') %Test for data type.

% Substitute NULL value for NullNumberWrite value

if (isempty(tmp) && isempty(nnw)) || (~isempty(nnw) && ~isempty(tmp) && tmp == nnw) || (isnan(tmp) && isnan(nnw))

tmpstr = 'NULL';

else

tmpstr = num2str(tmp,17);

end

% Numeric data.

if (j == cols), % Last column in the cell array.

% The final comma in the field string is not required.

dataString = [ dataString tmpstr ];

else

dataString = [ dataString tmpstr ',' ];

end

else

% Character/String data.

% Substitute NULL value for NullStringWrite value

if (isempty(tmp) && isempty(nsw)) || strcmp(tmp,nsw)

tmpstr = 'NULL';

else

tmpstr = ['''' tmp ''''];

end

if (j == cols), % Last column in the cell array.

% The final comma in the field string is not required.

dataString= [ dataString tmpstr];

else

dataString= [ dataString tmpstr ','];

end

end

end % End of cols loop

writeString = [startOfString dataString ' )'];

% Now insert the data into the database.

cursTemp=exec(connect,writeString);

if isa(cursTemp.Cursor,'com.mathworks.toolbox.database.sqlExec'),

% Close the cursor.

close(cursTemp);

else

% Stop the insertion process there is a problem

% with the SQL statement.

error('database:database:cursorError','%s',cursTemp.Message);

end

end  % End of numberOfRows loop

这是函数代码

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值