I have to insert value into table at runtime ?
-
CSting strid = m_strStringArr.getat(i); T("INSERT INTO tablename (setid) VALUES('strAnsi')"); This is my query and i get table field and its value at runtime.So how to insert this value.any idea about it..means Setid and stransi i get at runtime..
modified on Monday, September 14, 2009 6:37 AM
-
CSting strid = m_strStringArr.getat(i); T("INSERT INTO tablename (setid) VALUES('strAnsi')"); This is my query and i get table field and its value at runtime.So how to insert this value.any idea about it..means Setid and stransi i get at runtime..
modified on Monday, September 14, 2009 6:37 AM
Use CString::Format[^] to create the string.
CString cs;
cs.Format(_T("INSERT INTO tablename (%s) VALUES('%s')"), setid, strAnsi);«_Superman_» I love work. It gives me something to do between weekends.
-
CSting strid = m_strStringArr.getat(i); T("INSERT INTO tablename (setid) VALUES('strAnsi')"); This is my query and i get table field and its value at runtime.So how to insert this value.any idea about it..means Setid and stransi i get at runtime..
modified on Monday, September 14, 2009 6:37 AM
Do you really :omg: mean this
CString strTable = _T("MyRuntimeValueForTable");
CString strData = _T("MyRuntimeValueForData");CString strQuery;
strQuery.Format(_T("INSERT INTO %s VALUES ('%s')"), strTable, strData);?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Use CString::Format[^] to create the string.
CString cs;
cs.Format(_T("INSERT INTO tablename (%s) VALUES('%s')"), setid, strAnsi);«_Superman_» I love work. It gives me something to do between weekends.
It Works.. Thanks Superman
-
It Works.. Thanks Superman
But after set this data to fields,every fields ti goes into new line.i dont want this.I want after new line it goes to next line or next record.So how to solve this problem..
-
But after set this data to fields,every fields ti goes into new line.i dont want this.I want after new line it goes to next line or next record.So how to solve this problem..
When
strAnsi
has_T("aaa\nbbb\nccc")
then want to make 3 records? Do you mean like this? If then, you must splitstrAnsi
at first and make and execute sql 3 times. For example;TCHAR* strData = strAnsi.GetBuffer(-1);
TCHAR* pToken = _tcstok(strAnsi, _T("\n"));
while (pToken) {
CString sql;
sql.Format(_T("INSERT INTO tablename (%s) VALUES('%s')"), setid, pToken);
// execute SQL here
}
strAnsi.ReleaseBuffer();Well, I dont feel good
VALUES('%s')
in above sql because of string escaping issue or SQL-injection problems. I usually use prepared statements or parameterized query for this purpose.