Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Need help.

Need help.

Scheduled Pinned Locked Moved C#
csharpdatabasehelp
12 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mjawadkhatri
    wrote on last edited by
    #1

    I want to run this type of query in c# how i do please tell me. select empid,sysdte from timemgmt,if the select returns 0 rows then insert row else don't insert.

    A 1 Reply Last reply
    0
    • M mjawadkhatri

      I want to run this type of query in c# how i do please tell me. select empid,sysdte from timemgmt,if the select returns 0 rows then insert row else don't insert.

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      Did you tried anything to implement it ?

      cheers, Abhijit CodeProject MVP Web Site:abhijitjana.net My Latest Article : IIS Remote Debugging

      M 1 Reply Last reply
      0
      • A Abhijit Jana

        Did you tried anything to implement it ?

        cheers, Abhijit CodeProject MVP Web Site:abhijitjana.net My Latest Article : IIS Remote Debugging

        M Offline
        M Offline
        mjawadkhatri
        wrote on last edited by
        #3

        No I not tried to implement any thing.

        M K 2 Replies Last reply
        0
        • M mjawadkhatri

          No I not tried to implement any thing.

          K Offline
          K Offline
          K0306
          wrote on last edited by
          #4

          Try the sample code

                  SqlConnection con = new SqlConnection("your connection string");
                  SqlDataReader dr;
                  string str = "your query";
                  SqlCommand cmd = new SqlCommand(str, con);
                  dr = cmd.ExecuteReader();
                  if (dr.HasRows== false)
                  {
                      //insert new row
                  }
          

          Regards, Karthik K...

          M 2 Replies Last reply
          0
          • M mjawadkhatri

            No I not tried to implement any thing.

            M Offline
            M Offline
            Mycroft Holmes
            wrote on last edited by
            #5

            mjawadkhatri wrote:

            No I not tried to implement any thing.

            Why not. What are you going to run the select against, a List<> or datatable/view. You can use Linq or Rowfilter for the first part and the second is standard CRUD work.

            Never underestimate the power of human stupidity RAH

            M 1 Reply Last reply
            0
            • K K0306

              Try the sample code

                      SqlConnection con = new SqlConnection("your connection string");
                      SqlDataReader dr;
                      string str = "your query";
                      SqlCommand cmd = new SqlCommand(str, con);
                      dr = cmd.ExecuteReader();
                      if (dr.HasRows== false)
                      {
                          //insert new row
                      }
              

              Regards, Karthik K...

              M Offline
              M Offline
              mjawadkhatri
              wrote on last edited by
              #6

              I Am using oracle database using same codeing???

              K 1 Reply Last reply
              0
              • M Mycroft Holmes

                mjawadkhatri wrote:

                No I not tried to implement any thing.

                Why not. What are you going to run the select against, a List<> or datatable/view. You can use Linq or Rowfilter for the first part and the second is standard CRUD work.

                Never underestimate the power of human stupidity RAH

                M Offline
                M Offline
                mjawadkhatri
                wrote on last edited by
                #7

                i want to do Accept employee ID in one time in a day 2nd time user give same Id in a same date not accepted. this is my coding string MyString; MyString = "Select * from timemgmt"; if (radioin.Checked == true) { cn = new OdbcConnection("Driver={Microsoft ODBC for Oracle};Server=orcl;UID=it;PWD=cr;"); cmd = new OdbcCommand(MyString, cn); cn.Open(); cmd.CommandText = "insert into timemgmt values('" + textBox1.Text + "','" + label19.Text + "','" + label18.Text + "','" + label18.Text + "')"; cmd.ExecuteNonQuery(); cn.Close(); xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx textbox1.text = employe ID label19.text = System Date label18.text = System Time

                M 1 Reply Last reply
                0
                • M mjawadkhatri

                  I Am using oracle database using same codeing???

                  K Offline
                  K Offline
                  K0306
                  wrote on last edited by
                  #8

                  For Oracle, replace SqlConnection,SqlCommand,SqlDatareader to odbcConnection,odbccommand and odbcdatareader

                          odbcConnection con = new odbcConnection("your connection string");
                          odbcDataReader dr;
                          string str = "your query";
                          odbcCommand cmd = new odbcCommand(str, con);
                          dr = cmd.ExecuteReader();
                          if (dr.HasRows== false)
                          {
                              //insert new row
                          }
                  

                  Regards, Karthik K...

                  M 1 Reply Last reply
                  0
                  • K K0306

                    Try the sample code

                            SqlConnection con = new SqlConnection("your connection string");
                            SqlDataReader dr;
                            string str = "your query";
                            SqlCommand cmd = new SqlCommand(str, con);
                            dr = cmd.ExecuteReader();
                            if (dr.HasRows== false)
                            {
                                //insert new row
                            }
                    

                    Regards, Karthik K...

                    M Offline
                    M Offline
                    mjawadkhatri
                    wrote on last edited by
                    #9

                    Sir When I Use Ur Above Coding In my Aplication show error Error Is 'Microsoft.Data.Odbc.OdbcDataReader' does not contain a definition for 'HasRows'

                    1 Reply Last reply
                    0
                    • K K0306

                      For Oracle, replace SqlConnection,SqlCommand,SqlDatareader to odbcConnection,odbccommand and odbcdatareader

                              odbcConnection con = new odbcConnection("your connection string");
                              odbcDataReader dr;
                              string str = "your query";
                              odbcCommand cmd = new odbcCommand(str, con);
                              dr = cmd.ExecuteReader();
                              if (dr.HasRows== false)
                              {
                                  //insert new row
                              }
                      

                      Regards, Karthik K...

                      M Offline
                      M Offline
                      mjawadkhatri
                      wrote on last edited by
                      #10

                      Yes I M doing Same But give error 'Microsoft.Data.Odbc.OdbcDataReader' does not contain a definition for 'HasRows'

                      K 1 Reply Last reply
                      0
                      • M mjawadkhatri

                        Yes I M doing Same But give error 'Microsoft.Data.Odbc.OdbcDataReader' does not contain a definition for 'HasRows'

                        K Offline
                        K Offline
                        K0306
                        wrote on last edited by
                        #11

                        Then instead of Hasrow,use like this replace the below code

                                if (dr.HasRows == false)
                                {
                                    //insert new row
                                }
                        

                        new code

                                if (!dr.Read())
                                {
                                    MessageBox.Show("No records");
                                }
                                else
                                {
                                    MessageBox.Show("Records Found");
                                }
                        

                        Regards, Karthik K...

                        1 Reply Last reply
                        0
                        • M mjawadkhatri

                          i want to do Accept employee ID in one time in a day 2nd time user give same Id in a same date not accepted. this is my coding string MyString; MyString = "Select * from timemgmt"; if (radioin.Checked == true) { cn = new OdbcConnection("Driver={Microsoft ODBC for Oracle};Server=orcl;UID=it;PWD=cr;"); cmd = new OdbcCommand(MyString, cn); cn.Open(); cmd.CommandText = "insert into timemgmt values('" + textBox1.Text + "','" + label19.Text + "','" + label18.Text + "','" + label18.Text + "')"; cmd.ExecuteNonQuery(); cn.Close(); xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx textbox1.text = employe ID label19.text = System Date label18.text = System Time

                          M Offline
                          M Offline
                          Mycroft Holmes
                          wrote on last edited by
                          #12

                          You need to read this article on SQL Injection[^]

                          Never underestimate the power of human stupidity RAH

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups