I am trying to insert data into MSSQL through matlab and i am unable to pass the string values to the table.Here is my code:
username = get(handles.edit1,'String'); %edit1 being Tag of ur edit box
password= get(handles.edit2,'String'); %edit1 being Tag of ur edit box
confirm_pass = get(handles.edit3,'String'); %edit1 being Tag of ur edit box
email = get(handles.edit4,'String'); %edit1 being Tag of ur edit box
import System.Data.SqlClient.*
NET.addAssembly('System.Data');
conn = SqlConnection('Data Source=.;Initial Catalog=Ear;Integrated Security=true;');
conn.Open();
cmd = SqlCommand('insert into Register(username,password,confirm_pass,email) values(@username,2,2,4)', conn);
cmd.Parameters.AddWithValue('@username', username.Value);
r = cmd.ExecuteReader();
r.Close()
conn.Close()
I am able to execute the code if i pass the values directly as follows:
cmd = SqlCommand('insert into Register(username,password,confirm_pass,email) values(1,2,2,4)', conn);
Any help would be appreciated.Thank you!
Edit:
username = get(handles.edit1,'String'); %edit1 being Tag of ur edit box
password= get(handles.edit2,'String'); %edit1 being Tag of ur edit box
confirm_pass = get(handles.edit3,'String'); %edit1 being Tag of ur edit box
email = get(handles.edit4,'String'); %edit1 being Tag of ur edit box
import System.Data.SqlClient.*
NET.addAssembly('System.Data');
conn = SqlConnection('Data Source=.;Initial Catalog=Ear;Integrated Security=true;');
conn.Open();
cmd = SqlCommand('insert into Register(username,password,confirm_pass,email) values(username,password,confirm_pass,email)', conn);
r = cmd.ExecuteReader();
r.Close()
conn.Close()
This is my Error:
Error using Register>pushbutton2_Callback (line 214) Message: Invalid column name 'username'.
Invalid column name 'password'.
Invalid column name 'confirm_pass'.
Invalid column name 'email'. Source: .Net SqlClient Data Provider HelpLink:
Error in gui_mainfcn (line 96) feval(varargin{:});
Error in Register (line 42) gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)Register('pushbutton2_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
Table: id -int username -varchar(50) password -varchar(50) confirm_passs-varchar(50) email -varchar(50)