Click here to Skip to main content
15,922,015 members
Home / Discussions / Database
   

Database

 
GeneralSelect reads from XML file in ado.net Pin
imran_shahid@msn.com18-Nov-03 21:24
imran_shahid@msn.com18-Nov-03 21:24 
Questionhow to apply filter to Master/Detail records in dataset Pin
imran_shahid@msn.com18-Nov-03 21:19
imran_shahid@msn.com18-Nov-03 21:19 
AnswerRe: how to apply filter to Master/Detail records in dataset Pin
gokselm22-Nov-03 14:31
gokselm22-Nov-03 14:31 
GeneralCursor Pin
Anonymous18-Nov-03 4:42
Anonymous18-Nov-03 4:42 
GeneralRe: Cursor Pin
Jeff Varszegi18-Nov-03 5:34
professionalJeff Varszegi18-Nov-03 5:34 
Generalcall ado nextrecordset failed Pin
zhangxinghai17-Nov-03 21:52
zhangxinghai17-Nov-03 21:52 
Questionhow to store xml data from xml file in database table Pin
Kris{PL}17-Nov-03 11:55
Kris{PL}17-Nov-03 11:55 
GeneralBorland C++ Builder DB usage Pin
EricCartman17-Nov-03 5:43
EricCartman17-Nov-03 5:43 
Help!

I'm moving some code to C++ Builder and a small part of the code
is database stuff and I can't get it done. The code is really
simple but since it is database stuff it is virtually impossible
to find good example code (at least for me. I spent hours looking
thru examples, online, etc.) Everything is forms and controls.
I want to do it without that stuff. Like I said, this is just
a small part of the application and I really can't have any form
or user interface stuff.

Here is the code I want in C# for a Microsoft environment. I'd
like it to be in a Borland C++ Builder environment. Can you help?

Note it does the usual (for me!) stuff. Opens/closes a db, does
a standard SQL query (Select) with parameters and sorting, inserts,
and updates. All under program control, no user interface. I left
out a lot of error checking for clarity.

//Class vars
OleDbConnection m_conn;
int m_IDate[200];
string m_UniName;
float m_avalue[200];
m_uninames[200];
int m_cnt;
int m_dbcnt;

public void OpenIt()
{
string source = @"Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;";
source += @"Data Source=C:\xdata\";
source += "alltables.mdb;";
source += "Mode=ReadWrite;";
OleDbConnection m_conn = new OleDbConnection(source);
m_conn.Open();
}

public void CloseIt()
{
m_conn.Close();
}

public void Updateit(int j)
{
int astatus = 2;
string sSQLCommand = "UPDATE ATable SET Status = ? WHERE ";
sSQLCommand += "IDate = ? AND UniName = ? And AValue = ?";

OleDbCommand cmd;
cmd = new OleDbCommand();
cmd.CommandText = sSQLCommand;
cmd.Connection = m_conn;
cmd.Parameters.Clear();
cmd.Parameters.Add ( "Status", astatus) ;
cmd.Parameters.Add ( "IDate", m_IDate[j]) ; // int
cmd.Parameters.Add ( "UniName", m_UniName) ; // string
cmd.Parameters.Add ( "AValue", m_avalue[j]) ; // float

cmd.ExecuteNonQuery() ;
}

GetIt(int adate)
{
string selectname = "SELECT * FROM ATable Where IDate=?";
selectname += " ORDER BY UniName";

OleDbDataReader aReader;
OleDbCommand cmd;
cmd = new OleDbCommand();

cmd.CommandText = selectname;
cmd.Connection = m_conn;
cmd.Parameters.Clear();
cmd.Parameters.Add ( "IDate", adate) ;
aReader = cmd.ExecuteReader();

int j, k;
while(aReader.Read())
{
j = aReader.GetOrdinal("IDate");
k = aReader.GetInt32(j);
if (k != adate)
{
// this should not happen
continue;
}
j = aReader.GetOrdinal("UniName");
if (!aReader.IsDBNull(j))
m_uninames[m_cnt] = "";
else
m_uninames[m_cnt] = aReader.GetString(j);
j = aReader.GetOrdinal("AValue");
m_avalue[m_cnt] = aReader.GetFloat(j);
m_cnt++;
}

aReader.Close();
}

public void InsertIt(int adate, string uniname, int status, float avalue)
{
string strInsert = "INSERT INTO ATable ";
strInsert += "(Status, IDate, UniName, AValue) ";
strInsert += "VALUES (?, ?, ?, ?)";
OleDbCommand cmd;
cmd = new OleDbCommand(strInsert , m_conn);
cmd.Parameters.Add ("IDate", adate) ;
cmd.Parameters.Add ("UniName", uniname) ;
cmd.Parameters.Add ("Status", status) ;
cmd.Parameters.Add ("AValue", avalue) ;
cmd.ExecuteNonQuery() ;
m_dbcnt++;
}

GeneralSQLObjectListPtr Pin
ranjjj17-Nov-03 3:14
ranjjj17-Nov-03 3:14 
GeneralSQLObjectListPtr Pin
ranjjj17-Nov-03 3:14
ranjjj17-Nov-03 3:14 
Generalsqldmo.tlh Pin
ranjjj16-Nov-03 22:33
ranjjj16-Nov-03 22:33 
Generallistdatabasepermissions Pin
ranjjj15-Nov-03 23:53
ranjjj15-Nov-03 23:53 
GeneralLoad a file into a binary column in SQL server Pin
CillyMe15-Nov-03 17:32
CillyMe15-Nov-03 17:32 
GeneralRe: Load a file into a binary column in SQL server Pin
mhmoud rawas15-Nov-03 18:39
mhmoud rawas15-Nov-03 18:39 
GeneralRe: Load a file into a binary column in SQL server Pin
CillyMe16-Nov-03 22:32
CillyMe16-Nov-03 22:32 
GeneralLoad a file into a binary column in SQL server Pin
CillyMe15-Nov-03 17:31
CillyMe15-Nov-03 17:31 
GeneralRe: Load a file into a binary column in SQL server Pin
Jeff Varszegi18-Nov-03 5:38
professionalJeff Varszegi18-Nov-03 5:38 
GeneralSQL Server Date Problem Pin
sim_san15-Nov-03 1:16
sim_san15-Nov-03 1:16 
GeneralRe: SQL Server Date Problem Pin
Mike Dimmick15-Nov-03 1:55
Mike Dimmick15-Nov-03 1:55 
GeneralRe: SQL Server Date Problem Pin
sim_san17-Nov-03 6:40
sim_san17-Nov-03 6:40 
GeneralRe: SQL Server Date Problem Pin
Mike Dimmick17-Nov-03 6:54
Mike Dimmick17-Nov-03 6:54 
GeneralRe: SQL Server Date Problem Pin
sim_san22-Nov-03 6:23
sim_san22-Nov-03 6:23 
GeneralRe: SQL Server Date Problem Pin
Anonymous21-Nov-03 5:45
Anonymous21-Nov-03 5:45 
GeneralsqlDataAdapter Wizard does not Update Pin
Bruce L. Scheffler14-Nov-03 11:39
sussBruce L. Scheffler14-Nov-03 11:39 
GeneralJoin Pin
Anonymous14-Nov-03 8:25
Anonymous14-Nov-03 8:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.