Solved

C# with database

Posted on 2014-04-09
10
163 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
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!

 
LVL 1

Author Comment

by:Moti Mashiah
ID: 39990571
Perfect!!
0
 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

733 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