how to add auto generate number using sql

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • siddarthan
    New Member
    • Oct 2012
    • 5

    #1

    how to add auto generate number using sql

    I have an asp.net project with sql backend.

    I generate auto number using the code which has been given already, but it shown an error caused by giving the line in my code:
    Code:
    "Select @@identity;" in
    The error is...
    Keyword, identifier, or string expected after verbatim specifier: @
    Last edited by Frinavale; Oct 25 '12, 01:43 PM. Reason: Corrected grammar and added code tags.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    It would help to see the code. And also help to know which SQL backend you're using as there are many. Is it MySQL? Oracle? SQL Server? DB2? Some other one?

    Comment

    • siddarthan
      New Member
      • Oct 2012
      • 5

      #3
      mine is sql server 2000.and the particular field must have primary key or its optional

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        What about the code I asked for?

        Comment

        • siddarthan
          New Member
          • Oct 2012
          • 5

          #5
          Code:
          string query5 = "select prostock from inventory where Proname='" + pnamedrp.Text + " ' and prostock=prostock<75";
                  {
                      Response.Write("<script>alert('Purchase Product')</script>");
                  }
                      SqlCommand comd = new SqlCommand("insert into sales values(@billno,@Cid,@Proid,@Proname,@protype,@sellingprice,@quantity,@cost)", con);
                      comd.Parameters.AddWithValue("@billno", billno.Text);
                      comd.Parameters.AddWithValue("@Cid", custrid.Text);
                      comd.Parameters.AddWithValue("@Proid", procode.Text);
                      comd.Parameters.AddWithValue("@Proname", pnamedrp.SelectedItem.Text);
                      comd.Parameters.AddWithValue("@protype", protypee.SelectedItem.Text);
                      comd.Parameters.AddWithValue("@sellingprice", proprice.Text);
                      comd.Parameters.AddWithValue("@quantity", proqunty.Text);
                      comd.Parameters.AddWithValue("@cost", amt.Text);
                      comd.ExecuteNonQuery();
                      con.Close();
          in this billno want to generate automatically.
          Last edited by Meetee; Oct 24 '12, 06:22 AM. Reason: please add code tags <code/> around your code

          Comment

          • siddarthan
            New Member
            • Oct 2012
            • 5

            #6
            Code:
            protected void insrtbtn_Click(object sender, EventArgs e)
                {
                    dataTable.Rows.Add(procode.Text, pnamedrp.SelectedItem.Text, protypee.SelectedItem.Text, proprice.Text, proqunty.Text, amt.Text + "");
                    salegrid.DataSource = dataTable;
                    salegrid.DataBind();
                    setupTable();
                    updateTotal();
                    con.Open();
                    string query5 = "select prostock from inventory where Proname='" + pnamedrp.Text + " ' and prostock=prostock<75";
                    {
                        Response.Write("<script>alert('Purchase Product')</script>");
                    }
                        SqlCommand comd = new SqlCommand("insert into sales values(@billno,@Cid,@Proid,@Proname,@protype,@sellingprice,@quantity,@cost)", con);
                        comd.Parameters.AddWithValue("@billno", billno.Text);
                        comd.Parameters.AddWithValue("@Cid", custrid.Text);
                        comd.Parameters.AddWithValue("@Proid", procode.Text);
                        comd.Parameters.AddWithValue("@Proname", pnamedrp.SelectedItem.Text);
                        comd.Parameters.AddWithValue("@protype", protypee.SelectedItem.Text);
                        comd.Parameters.AddWithValue("@sellingprice", proprice.Text);
                        comd.Parameters.AddWithValue("@quantity", proqunty.Text);
                        comd.Parameters.AddWithValue("@cost", amt.Text);
                        comd.ExecuteNonQuery();
                        con.Close();
            
                        // Write query for stock update
            
                        con.Open();
                        SqlCommand cmd = new SqlCommand("update inventory set prostock=prostock-" + proqunty.Text + " where Proid='" + procode.Text + "';", con);
                        cmd.ExecuteNonQuery();
                        con.Close();               
                }
            in this bill no want to generate automatically. may be more one product can buy in same bill no
            Last edited by Meetee; Oct 24 '12, 06:22 AM. Reason: code tags added

            Comment

            • Rabbit
              Recognized Expert MVP
              • Jan 2007
              • 12517

              #7
              I don't see @@identity anywhere in your code. At this point, I don't know what your question is anymore.

              Comment

              • siddarthan
                New Member
                • Oct 2012
                • 5

                #8
                i got answer in some other way.. thank you..

                Comment

                • Rabbit
                  Recognized Expert MVP
                  • Jan 2007
                  • 12517

                  #9
                  Could you post that answer here in case someone else stumbles upon this thread?

                  Comment

                  Working...