Solved

C# with database

Posted on 2014-04-09
10
161 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
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.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

777 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