Click here to Skip to main content
15,916,683 members
Home / Discussions / Database
   

Database

 
GeneralRe: reset primary key (mysql) Pin
Jörgen Andersson28-Nov-10 10:21
professionalJörgen Andersson28-Nov-10 10:21 
GeneralRe: reset primary key (mysql) Pin
Luc Pattyn28-Nov-10 10:29
sitebuilderLuc Pattyn28-Nov-10 10:29 
AnswerRe: reset primary key (mysql) Pin
Hiren solanki1-Dec-10 22:32
Hiren solanki1-Dec-10 22:32 
QuestionHow to get Column Value From a Statement if Table Name passes dynamically through a variable....? Pin
Manish_Kumar_Nayak25-Nov-10 20:33
Manish_Kumar_Nayak25-Nov-10 20:33 
AnswerRe: How to get Column Value From a Statement if Table Name passes dynamically through a variable....? Pin
Mycroft Holmes25-Nov-10 20:45
professionalMycroft Holmes25-Nov-10 20:45 
GeneralRe: How to get Column Value From a Statement if Table Name passes dynamically through a variable....? Pin
Manish_Kumar_Nayak25-Nov-10 20:48
Manish_Kumar_Nayak25-Nov-10 20:48 
GeneralRe: How to get Column Value From a Statement if Table Name passes dynamically through a variable....? Pin
PIEBALDconsult26-Nov-10 6:39
mvePIEBALDconsult26-Nov-10 6:39 
QuestionSQL statement Pin
Tichaona J25-Nov-10 2:31
Tichaona J25-Nov-10 2:31 
Hi I am using a SQL statement to access data from a database, if I hardcode a specific name in the field I get, the name being searched for is returned and displayed. Of-course this isn't a convient way of doing things so I introduced a text box to take in the data, store it in a variable then, this is were my problem lies, I try and used my variable in the SQL statement but it does not work. My code is as below:

<br />
static private string GetConnectionString()<br />
        {<br />
<br />
            return<br />
            "Driver={Microsoft Access Driver (*.mdb)};"<br />
                + "Dbq=c:\\Users\\Tichaona\\Documents\\My Dropbox\\SET10101  Software Architecture\\coursework1\\patients.mdb;Uid=java;Pwd=password;";<br />
        }<br />
<br />
        private void BtnSearch_Click(object sender, EventArgs e)<br />
        {<br />
            String nameSearch = TxtBxName.Text; <<<The variable I wish to use<br />
            try<br />
            {               <br />
<br />
                string connectionString = GetConnectionString();<br />
                string queryString = "SELECT Name FROM patients WHERE Name LIKE '%nameSearch%';"; <<<Here<br />
                using (OdbcConnection connection =<br />
                           new OdbcConnection(connectionString))<br />
                {<br />
                    OdbcCommand command = connection.CreateCommand();<br />
                    command.CommandText = queryString;<br />
<br />
<br />
                    try<br />
                    {<br />
                        connection.Open();<br />
<br />
                        OdbcDataReader reader = command.ExecuteReader();<br />
<br />
                        <br />
<br />
                        while (reader.Read())<br />
                        {<br />
<br />
                            LstBxResults.Items.Add(reader.GetString(0));<br />
<br />
                           <br />
                        }<br />
<br />
                        reader.Close();<br />
                    }<br />
<br />
                    catch (Exception ex)<br />
                    {<br />
                        MessageBox.Show(ex.Message);<br />
<br />
<br />
                    }<br />
                }<br />
            }//<br />
            catch (Exception er)<br />
            {<br />
                MessageBox.Show("There is an error {0}" + er);<br />
            }<br />
<br />
<br />
        }<br />
<br />
       <br />
    }<br />
}<br />
<br />
<br />

AnswerRe: SQL statement [modified] Pin
thatraja25-Nov-10 2:56
professionalthatraja25-Nov-10 2:56 
GeneralRe: SQL statement Pin
Tichaona J25-Nov-10 3:03
Tichaona J25-Nov-10 3:03 
GeneralRe: SQL statement Pin
PIEBALDconsult25-Nov-10 3:41
mvePIEBALDconsult25-Nov-10 3:41 
GeneralRe: SQL statement Pin
PIEBALDconsult25-Nov-10 3:40
mvePIEBALDconsult25-Nov-10 3:40 
GeneralRe: SQL statement Pin
thatraja25-Nov-10 3:51
professionalthatraja25-Nov-10 3:51 
GeneralRe: SQL statement Pin
PIEBALDconsult25-Nov-10 4:28
mvePIEBALDconsult25-Nov-10 4:28 
GeneralRe: SQL statement Pin
thatraja25-Nov-10 17:58
professionalthatraja25-Nov-10 17:58 
GeneralRe: SQL statement Pin
RaviRanjanKr25-Nov-10 15:35
professionalRaviRanjanKr25-Nov-10 15:35 
AnswerRe: SQL statement Pin
PIEBALDconsult25-Nov-10 3:39
mvePIEBALDconsult25-Nov-10 3:39 
QuestionHow to Get Value from Exec(Sql) in SQL Server 2005 if possible...? help me.... Pin
Manish_Kumar_Nayak25-Nov-10 2:03
Manish_Kumar_Nayak25-Nov-10 2:03 
AnswerRe: How to Get Value from Exec(Sql) in SQL Server 2005 if possible...? help me.... Pin
thatraja25-Nov-10 2:31
professionalthatraja25-Nov-10 2:31 
AnswerRe: How to Get Value from Exec(Sql) in SQL Server 2005 if possible...? help me.... Pin
Hiren solanki1-Dec-10 22:35
Hiren solanki1-Dec-10 22:35 
Questionvarchar(MAX) in mySQL Pin
Jassim Rahma25-Nov-10 1:35
Jassim Rahma25-Nov-10 1:35 
AnswerRe: varchar(MAX) in mySQL Pin
Luc Pattyn25-Nov-10 1:59
sitebuilderLuc Pattyn25-Nov-10 1:59 
QuestionAccess database to SQL Pin
KORCARI25-Nov-10 0:13
KORCARI25-Nov-10 0:13 
AnswerRe: Access database to SQL Pin
PIEBALDconsult25-Nov-10 3:43
mvePIEBALDconsult25-Nov-10 3:43 
AnswerRe: Access database to SQL Pin
Bernhard Hiller25-Nov-10 23:19
Bernhard Hiller25-Nov-10 23:19 

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.