?
Solved

C# with database

Posted on 2014-04-09
10
Medium Priority
?
166 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
10 Comments
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 1000 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 49

Assisted Solution

by:PortletPaul
PortletPaul earned 1000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Author Comment

by:Moti Mashiah
ID: 39990571
Perfect!!
0
 
LVL 49

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 49

Expert Comment

by:PortletPaul
ID: 39990668
Thanks!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

765 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