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
  1. Home
  2. General Programming
  3. C#
  4. finding error

finding error

Scheduled Pinned Locked Moved C#
helpdatabasesecuritytestingbeta-testing
5 Posts 4 Posters 0 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.
  • T Offline
    T Offline
    tittly
    wrote on last edited by
    #1

    hi all, i get error in my application .plz help to recover the error i add time in the database .before adding in database it check this time is already exit or not .if exits it don't allow me to add the same time again i have two comobox one for hour and second for minute and it contain int value.i get value from comobox and concatenate both value and send to database on running application it give me system error message private void btnAdd_Click(object sender, System.EventArgs e) { //cbxHr.Text hour combo box //cbxMin.Text min combo box SaveTiming(cbxHr.Text,cbxMin.Text); } private void SaveTiming(string hr, string std_min) { bool flag = false; string connectionString = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Testing;Data Source=(local)"; string test = hr+""+ std_min; string isExist = "SELECT * FROM timing WHERE s_time=" + test + ""; string sqlInst = "Insert into timing(s_test)Values(" + test + ")"; using (SqlConnection connection = new SqlConnection(connectionString)) { SqlCommand command = new SqlCommand(isExist, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { MessageBox.Show("Timing already has been assigned"); flag = true; } reader.Close(); if (!flag) { SqlCommand cmd = new SqlCommand(sqlInst, connection); cmd.ExecuteNonQuery(); } } }

    okey

    C G T 3 Replies Last reply
    0
    • T tittly

      hi all, i get error in my application .plz help to recover the error i add time in the database .before adding in database it check this time is already exit or not .if exits it don't allow me to add the same time again i have two comobox one for hour and second for minute and it contain int value.i get value from comobox and concatenate both value and send to database on running application it give me system error message private void btnAdd_Click(object sender, System.EventArgs e) { //cbxHr.Text hour combo box //cbxMin.Text min combo box SaveTiming(cbxHr.Text,cbxMin.Text); } private void SaveTiming(string hr, string std_min) { bool flag = false; string connectionString = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Testing;Data Source=(local)"; string test = hr+""+ std_min; string isExist = "SELECT * FROM timing WHERE s_time=" + test + ""; string sqlInst = "Insert into timing(s_test)Values(" + test + ")"; using (SqlConnection connection = new SqlConnection(connectionString)) { SqlCommand command = new SqlCommand(isExist, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { MessageBox.Show("Timing already has been assigned"); flag = true; } reader.Close(); if (!flag) { SqlCommand cmd = new SqlCommand(sqlInst, connection); cmd.ExecuteNonQuery(); } } }

      okey

      C Offline
      C Offline
      CodingYoshi
      wrote on last edited by
      #2

      Hi, Why did you not put the error you are getting? Anyhow, how are you storing the time in database--what is the type? If it is string then problem is in your sqlQuery: string isExist = "SELECT * FROM timing WHERE s_time=" + test + ""; string sqlInst = "Insert into timing(s_test)Values(" + test + ")"; Both will not work as strings need single quotes around them. Here is the correct version: string isExist = "SELECT * FROM timing WHERE s_time= '" + test + "'"; string sqlInst = "Insert into timing(s_test)Values('" + test + "')"; Hope it solves the issue. You should put your code in a try catch block when executing commands on database.

      1 Reply Last reply
      0
      • T tittly

        hi all, i get error in my application .plz help to recover the error i add time in the database .before adding in database it check this time is already exit or not .if exits it don't allow me to add the same time again i have two comobox one for hour and second for minute and it contain int value.i get value from comobox and concatenate both value and send to database on running application it give me system error message private void btnAdd_Click(object sender, System.EventArgs e) { //cbxHr.Text hour combo box //cbxMin.Text min combo box SaveTiming(cbxHr.Text,cbxMin.Text); } private void SaveTiming(string hr, string std_min) { bool flag = false; string connectionString = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Testing;Data Source=(local)"; string test = hr+""+ std_min; string isExist = "SELECT * FROM timing WHERE s_time=" + test + ""; string sqlInst = "Insert into timing(s_test)Values(" + test + ")"; using (SqlConnection connection = new SqlConnection(connectionString)) { SqlCommand command = new SqlCommand(isExist, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { MessageBox.Show("Timing already has been assigned"); flag = true; } reader.Close(); if (!flag) { SqlCommand cmd = new SqlCommand(sqlInst, connection); cmd.ExecuteNonQuery(); } } }

        okey

        G Offline
        G Offline
        gspiteri
        wrote on last edited by
        #3

        tittly wrote:

        string sqlInst = "Insert into timing(s_test)Values(" + test + ")";

        try: Insert into timing(s_test)Values('" + test + "')

        A pessimist sees the difficulty in every opportunity; an optimist sees the opportunity in every difficulty I am a Optimist

        1 Reply Last reply
        0
        • T tittly

          hi all, i get error in my application .plz help to recover the error i add time in the database .before adding in database it check this time is already exit or not .if exits it don't allow me to add the same time again i have two comobox one for hour and second for minute and it contain int value.i get value from comobox and concatenate both value and send to database on running application it give me system error message private void btnAdd_Click(object sender, System.EventArgs e) { //cbxHr.Text hour combo box //cbxMin.Text min combo box SaveTiming(cbxHr.Text,cbxMin.Text); } private void SaveTiming(string hr, string std_min) { bool flag = false; string connectionString = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Testing;Data Source=(local)"; string test = hr+""+ std_min; string isExist = "SELECT * FROM timing WHERE s_time=" + test + ""; string sqlInst = "Insert into timing(s_test)Values(" + test + ")"; using (SqlConnection connection = new SqlConnection(connectionString)) { SqlCommand command = new SqlCommand(isExist, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { MessageBox.Show("Timing already has been assigned"); flag = true; } reader.Close(); if (!flag) { SqlCommand cmd = new SqlCommand(sqlInst, connection); cmd.ExecuteNonQuery(); } } }

          okey

          T Offline
          T Offline
          tittly
          wrote on last edited by
          #4

          i use string type in data base when i run my application it stop on this statement SqlDataReader reader = command.ExecuteReader(); and show system error message

          okey

          C 1 Reply Last reply
          0
          • T tittly

            i use string type in data base when i run my application it stop on this statement SqlDataReader reader = command.ExecuteReader(); and show system error message

            okey

            C Offline
            C Offline
            C Coudou
            wrote on last edited by
            #5

            to know what is the error; use: try { ... } catch() { ... } finally() { }

            ****************************** The best things in life are free ******************************

            modified on Friday, April 4, 2008 3:14 AM

            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