Solved

C# with database

Posted on 2014-04-09
10
160 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
ID: 39990547
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
ID: 39990551
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
ID: 39990570
OH No I feel sooo stupid LOL.

Thank you very much it works now.
0
 
LVL 1

Author Comment

by:Moti Mashiah
ID: 39990571
Perfect!!
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 48

Expert Comment

by:PortletPaul
ID: 39990578
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
ID: 39990613
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
ID: 39990614
Please reopen the question
0
 
LVL 1

Author Closing Comment

by:Moti Mashiah
ID: 39990658
solved
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 39990668
Thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 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

22 Experts available now in Live!

Get 1:1 Help Now