Solved

C# with database

Posted on 2014-04-09
10
157 Views
Last Modified: 2014-04-09
Hi Guys ,

I have built new application and I'm trying to query some tables and columns from the database see could below: and also screenshot of my issue

string conn = "Data Source=srv-db-02;Initial Catalog=rmsmasterdbtest;Persist Security Info=True;User ID=test;Password=masterB4";
            //string Query = "select * from rmsmasterdbtest.dbo.PurchaseOrder where ponumber= '" + combopo.Text + "' ;";
            string Query = "select d.PONumber, b.ItemLookupCode, a.SerialNumber, a.SerialNumber2, a.SerialNumber3"
            + "from rmsmasterdbtest.from dbo.Serial AS A" 
            + "inner join dbo.item AS B on b.id = a.ItemID"
            + "inner join dbo.PurchaseOrderEntry AS C on C.ItemID = b.ID"
            + "inner join dbo.PurchaseOrder AS D on D.ID = c.PurchaseOrderID"
            + "where ponumber= '" + combopo.Text + "';";


            SqlConnection Myconn = new SqlConnection(conn);
            SqlCommand cmdDataBase = new SqlCommand(Query, Myconn);
            SqlDataReader Reader;

            try
            {
                Myconn.Open();
                Reader = cmdDataBase.ExecuteReader();
                if (Reader.Read())
                {

                    string stime = Reader.GetDateTime(Reader.GetOrdinal("SerialNumber2")).ToString();
                    string sstatus = Reader.GetString(Reader.GetOrdinal("SerialNumber3"));
                    
                    txtdate.Text = stime;
                    txtstatus.Text = sstatus;

Open in new window

Capture.JPG
0
Comment
Question by:Moti Mashiah
  • 5
  • 3
10 Comments
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 250 total points
Comment Utility
Add some spaces to the end of the lines of your sql query :

string Query = "select d.PONumber, b.ItemLookupCode, a.SerialNumber, a.SerialNumber2, a.SerialNumber3 "
            + "from rmsmasterdbtest.from dbo.Serial AS A "
            + "inner join dbo.item AS B on b.id = a.ItemID "
            + "inner join dbo.PurchaseOrderEntry AS C on C.ItemID = b.ID "
            + "inner join dbo.PurchaseOrder AS D on D.ID = c.PurchaseOrderID "
            + "where ponumber= '" + combopo.Text + "';";
0
 
LVL 48

Assisted Solution

by:PortletPaul
PortletPaul earned 250 total points
Comment Utility
or at the front of each line
(this is simply a preference, the answer above identifies the issue I believe)

string Query = "select d.PONumber, b.ItemLookupCode, a.SerialNumber, a.SerialNumber2, a.SerialNumber3"
            + " from rmsmasterdbtest.from dbo.Serial AS A" 
            + " inner join dbo.item AS B on b.id = a.ItemID"
            + " inner join dbo.PurchaseOrderEntry AS C on C.ItemID = b.ID"
            + " inner join dbo.PurchaseOrder AS D on D.ID = c.PurchaseOrderID"
            + " where ponumber= '" + combopo.Text + "';";

Open in new window

0
 
LVL 1

Author Comment

by:Moti Mashiah
Comment Utility
OH No I feel sooo stupid LOL.

Thank you very much it works now.
0
 
LVL 1

Author Comment

by:Moti Mashiah
Comment Utility
Perfect!!
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 48

Expert Comment

by:PortletPaul
Comment Utility
Oh dear, really the answer was from Paul Jackson, mine was just a preference.

I'm able to re-open this for you for a split of points, just ask.

btw: no need to feel silly, we have all done things like this, me all too often :)
0
 
LVL 1

Author Comment

by:Moti Mashiah
Comment Utility
Sorry guys I didn't pay attention I'm going to divide the point.

Thank you very much.
0
 
LVL 1

Author Comment

by:Moti Mashiah
Comment Utility
Please reopen the question
0
 
LVL 1

Author Closing Comment

by:Moti Mashiah
Comment Utility
solved
0
 
LVL 48

Expert Comment

by:PortletPaul
Comment Utility
Thanks!
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now