Click here to Skip to main content
15,119,897 members

Comments by Mike V Baker (Top 57 by date)

Mike V Baker 4-Sep-18 9:09am View
   
INSERT INTO ComicCharacters (FirstName, LastName) VALUES
("Bugs", "Bunny"),
("Yosemite", "Sam"),
("Elmer", "Fudd"),
("Grape", "Ape");

Start with the INSERT INTO line, then just keep listing the values in parens. When it reaches the batch size you run the cmd, clear it and start over. Use comma between records, semi-colon on the end. 1000 is an arbitrary number I picked so that I could show progress in the program.
Mike V Baker 4-Sep-18 9:08am View
   
Deleted
INSERT INTO ComicCharacters (FirstName, LastName) VALUES
("Bugs", "Bunny"),
("Yosemite", "Sam"),
("Elmer", "Fudd"),
("Grape", "Ape");

Start with the INSERT INTO line, then just keep listing the values in parens. When it reaches the batch size you run the cmd, clear it and start over. Use comma between records, semi-colon on the end. 1000 is an arbitrary number I picked so that I could show progress in the program.
Mike V Baker 4-Sep-18 9:05am View
   
Be aware that if you do disable the triggers and/or indexes during the operation then you'll need to rebuild the indexes and perform the operations in the triggers to ensure the data is correct.
Mike V Baker 4-Sep-18 9:01am View
   
INSERT INTO ComicCharacters (FirstName, LastName) VALUES
("Bugs", "Bunny"),
("Yosemite", "Sam"),
("Elmer", "Fudd"),
("Grape", "Ape");

Start with the INSERT INTO line, then just keep listing the values in parens. When it reaches the batch size you run the cmd, clear it and start over. Use comma between records, semi-colon on the end. 1000 is an arbitrary number I picked so that I could show progress in the program.
Mike V Baker 28-Aug-18 9:09am View
   
What I mean is that the cmd will only need to execute 8 queries instead of 8000. Even though each qry has 1000 records it still runs faster than 8000 single record inserts. Perhaps if you posted the SQL that the cmd will run I can show you what I mean
Mike V Baker 27-Aug-18 11:45am View
   
This question doesn't give me any clue what you're trying to do. In the 'What I have tried' section you need to include the code you're using, what you expect it to do, and what it's actually doing.
Mike V Baker 27-Aug-18 11:43am View
   
I don't understand what you mean by 'simple loop to match two dataset...'. Show us the code.
Mike V Baker 27-Aug-18 11:39am View
   
Can you create the sql file with 8 inserts of 1000 records each rather than 8000 inserts? What I usually do is set a threshhold like 1000 records. As I process items I keep count of how many inserts are in the list and when it reaches the threshold it runs that insert.
Mike V Baker 10-Aug-18 21:20pm View
   
SELECT Acctnumber, ChargeCode FROM PatientCharges WHERE ChargeCode LIKE '10%' AND AcctNumber NOT IN (SELECT DISTINT AcctNumber FROM PatientCharges WHERE ChargeCode NOT LIKE '10%');

?? Not sure about how long this will take. How many records we talking about? Is ChargeCode indexed?
Mike V Baker 10-Aug-18 10:29am View
   
You could use for (Sortiment filterableSortiment : map) rather than using i as iterator. But I don't think that would change your results, just a different way to iterate. Have you written the contents of your vars out to a log so you can verify that what you think you're looking for is there? My first debugging technique - verify the data. Dump the contents of map out to the console prior to running the loop, and dump the contents of filterableSortiment as it is being tested.
p.s. don't pre-init the filterMap to the same size as map. You'll never need that many unless all items match. Just create it empty, 'add' will expand it.
Mike V Baker 10-Aug-18 9:48am View
   
Why don't you want to create new instances of the AsyncTask? I believe the right way to do it is to create an AsyncTask, use it, let it go out of scope and get cleaned.
Mike V Baker 10-Aug-18 9:29am View
   
Have you already written the Android app that's going to use this database? How are you connecting now?
If you're connecting your android to the database through your local network in your office then you should be able to do so through a network connection regardless of physical location. You would need VPN software on the android to make the network available to your app.
Mike V Baker 10-Aug-18 9:08am View
   
The code that would invoke the save isn't posted so I'm not sure, but what I thought might be happening is that the save is triggered by some event in the grid. It appears that the event is being triggered for you when there's no currently selected record. So the controller gets called with a customer == null. Are you able to break the operation and view the call stack to see from where the update is being called?
Mike V Baker 9-Aug-18 12:36pm View
   
"...when I select in the view to add a row it is actually calling the edit in the controller.."
Is it possible that it thinks you have edited the row that's losing focus? You click view to add a new record. In order to do that it has to leave the record that was selected on startup...? What's the value of customer at that point? Perhaps it's null and all you need is a check for a null entity to exit.
Mike V Baker 6-Aug-18 16:04pm View
   
There are just too many unknowns here to be able to provide you a good answer. M4rLask's answer is great if you want your user(s) (how many of them are there?) to each require WAMP on their system. As a user, I would not want to have to go through that. Also, it would mean that each of your users would be using their own copy of the database. If you want all your users to be able to access the same database then web hosting is one direction you could use. You could also set up the database and the Java application on AWS (Amazon Web Services). AWS would host both the application and the database and you would change your connection info to refer to the online copy of the DB and not the local one.
Mike V Baker 3-Aug-18 15:22pm View
   
@OP - Are you saying that the first two calls to the database work but the third one that uses the parameterized query doesn't work? If that's the case then I don't know why it would complain about the context being disposed. If it's failing on all three because you're running this outside the normal process then using a locally created dbcontext will be the answer.
I do have a question about the last part of the query - AND LookUpValue = @value - what type is LookUpValue, text? Perhaps it should be AND LookUpValue = '@value' ??
Mike V Baker 3-Aug-18 15:10pm View
   
Oops. You are correct. Sorry, I was thinking of a different conversation.
Mike V Baker 3-Aug-18 13:20pm View
   
Raw queries are open to SQL injection attacks so I try to avoid them like the plague. I usually create either a view or a stored procedure and import that into my EF data model.
In the past (long past) I used a .NET data access layer that didn't use EF and it had support raw queries. Let me think... that was 2008... I used articles by David C. Veeneman I believe.
public static DataSet GetDataSet(string sqlQuery)
{
DataSet dataSet = new DataSet();
SqlConnection conn = GetConnection();
SqlCommand cmd;
if (conn != null)
{
using (conn)
{
cmd = conn.CreateCommand();
cmd.CommandText = sqlQuery;
SqlDataAdapter dataAdapter = new SqlDataAdapter(cmd);
dataAdapter.Fill(dataSet);
}
cmd.Dispose();
conn.Close();
conn.Dispose();
}
// return dataset
return dataSet;
}
I don't know if you want to bring in another library. Could be your application already uses SqlDataAdapter so another lib reference might not be needed.
Mike V Baker 2-Aug-18 9:45am View
   
Have you tried putting it in OnResume instead of OnCreate? Two reasons. OnCreate might be too early in the life cycle for what you're trying to do, and OnResume will also run it when they switch from one app to another and return. If you don't want it to pull up a new add in OnResume then perhaps OnCreateView would work.
Mike V Baker 2-Aug-18 9:35am View
   
I don't understand why the LookUps is being treated differently than the Empmasters or Empmaster.
int value = empersonal.Gender;
var temp = enitites.LookUps.Where(p => p.LookUpType=='GENDER' && p.LookUpValue==value);
var Gender = temp.LookupName;
Mike V Baker 1-Aug-18 10:54am View
   
Thanks for the notes. I got both of those parts from other posts. If there's a more elegant way, please post it so we can all learn from it. [EDIT] - I see now that you already posted it in solution #3, must have been while I was testing mine. I think I like the last one that uses sys.all_objects.
Mike V Baker 1-Aug-18 9:04am View
   
There's a lot of code here but where's the problem? Where's the code you're using to try and clear the user data? Try cutting down the code you post to just what's involved in the problem.
Mike V Baker 1-Aug-18 8:34am View
   
We can't tell from this where you're having the problem. You need to tell us where your problem is and post some *relevant* code.
Mike V Baker 1-Aug-18 8:29am View
   
I don't understand why you put in this code. I was asking what's in the data.
Mike V Baker 31-Jul-18 22:13pm View
   
When you run this code, what do you expect to see in currentEntry and what actually winds up in currentEntry?
These are passwords? And you're writing them to a text file? No encryption? I suggest a re-think there.
Mike V Baker 31-Jul-18 11:48am View
   
Sounds like your array is empty. What's the result of NSLog jsondata? Is there a 'data' value? Is it an array [ ] or an object { }?
Mike V Baker 31-Jul-18 11:37am View
   
I'm not sure I get this.. "SELECT SUM(@Price)*SUM(@Qty)FROM Laptops WHERE ID_Lap=@ID" isn't selecting anything from Laptops. It's calculating the passed in params, no? What this appears to be doing is setting the totale to the sum of those values based on the number of those items found in the DB regardless of what price and qty might be in those records.
If you do change it so that it does select from the Laptops records then you should remember that SUM(price)*SUM(qty) does not equal SUM(price * qty). For example if you have two records, qty 5 price $100 and qty 6 price $1, then 5 * 100 + 6 * 1 <> 11 * 101
The table of desired output appears to be gathering data based on Brand+Series+Model (and perhaps Ram+HDD) but the WHERE clause is using ID_Lap. Is the ID_Lap a composite key of those items? If not then you're only getting one record rather than all records with those features.
Mike V Baker 29-Jul-18 12:44pm View
   
Create a SP in the sql server database that takes the list of products id's in a single param?
Mike V Baker 29-Jul-18 11:29am View
   
They're asking if the types of data you're comparing are both 'text' type. I'm going to assume that both (String)row.Cells["Month"].Value and birthdayMonth.Text are text type items.
It appears that you've created a DataTable and set that as the DataSource for the grid. To filter the contents of the grid you want to take action on the list, so look for functions in DataTable supporting filter. I usually use a n-tier system and my data sources are List<mytype> so I'm not sure which function to call (or I would post it as a solution). You might also need to call the grid BindingSource.ResetBindings
Mike V Baker 23-Jul-18 11:57am View
   
Your Form4 creates a new Form3. It doesn't call the function that you're trying to run.
BTW your function is making the same comparison 141 times. I would test Program.SampiyonAdi == Sampiyonlar first and then run through the i = 0 to 141 only if that's true.
Mike V Baker 23-Jul-18 10:43am View
   
I haven't used the TableLayout, all my tabular data is shown in RecylerView with RecyclerView.Adapter to handle the data. One suggestion that I can make is that OnCreate might be too early in the life cycle for AddData. You will probably want to move that to OnResume. You also want it in OnResume because if you change screens and then change back again, OnResume is called but OnCreate is not.
I don't see in your code the place where your 'start' function is called. Is that supposed to be OnStart?
Have you put in breakpoints and debugged the app at the end of 'start' and the end of 'addData' to verify what you have to work with?
Mike V Baker 19-Jul-18 13:22pm View
   
A Web API service written in C# will return data in a specific format (typically XML or JSON) in response to HTTP requests. You can access the service from either a .NET MVC app or an app written in PHP. The language used to write the clients consuming the service is irrelevant to the language used in the service. There are libraries in both .NET and in PHP to retrieve and parse the results into something you can use in your app.
Mike V Baker 19-Jul-18 13:00pm View
   
I don't think I would trust the results given the columns you're describing here. The reason being that you're concerned with 1st entry, 2nd entry, 3rd entry, etc for each state and you're relying on 'natural order' to figure out which is 1st and 2nd. You don't have any indexing to control what's 1st, 2nd, 3rd.... To my knowledge there's nothing that guarantees the results will come to you in that natural order when you query. You have to create a column such as EntryOrder to use as a control and sort. You could create a composite index on ID + State + EntryOrder. (If I were doing this I'd consider using a separate table and a foreign key for states.) [1,OH,1], [1,OH,2], [1,CO,1], [1,CO,2], [1,NC,1], [1,NC,2]. Even after doing that I'm not sure it can be done in a single shot of sql. You can order by ID, EntryOrder, State to get them in the right order, group by ID, and EntryOrder and then concatenate the types and put the result in a temporary table. Then select from the table where the concatenated types are not equal. There's something else I was just looking at here https://stackoverflow.com/questions/273238/how-to-use-group-by-to-concatenate-strings-in-sql-server but I'm not sure it'll work for you. It doesn't include the comparison component.
Mike V Baker 18-Jul-18 11:07am View
   
I see here code to fill the table from a data source. I can't see the SQL for the "individual_attendance" SP. Is there a LEFT OUTER JOIN in there so that the students will come in but there will be NULL for 'Attendance_id' if they haven't checked in? In that case the P/A will be Attendance_id == null ? "Absent" : "Present"
Mike V Baker 18-Jul-18 10:53am View
   
As I read your description I'm confused by the records you believe would be in the result set. Take for example ID 1. You have records where the ID and the state match. 1 & OH, 1 & CO, 1 & NC. The types of each of these records do not match Ret <> DetRet. This is true for each of these sets so all these six records for ID 1 would qualify ID=ID AND State=State AND Type<>Type. The only ones that I see that would NOT fall into this are ID3 & State CA, and ID4 & State PA. Those are the only ones that would be excluded according to your criteria since their types are equal.
Mike V Baker 17-Jul-18 12:31pm View
   
I would like to concur w/David and add that you do not need to compile to 17 in order to support back to 17. You should always have your compile target set to support up to the most current version and put the earliest version you want to support into your "Min SDK Version" of the project structure dialog's flavors tab.
Mike V Baker 13-Jul-18 9:12am View
   
Have you tried typing the URL into a browser? When I do that with my services I get a json file with the contents that the app will get. (assuming it's returning json)

How long have you waited for the response from the server when you're running the Android app? In my case the timeout value is something very long.

OH! What about this in your SqlCommand? "SELECT * from Password"

Is that a typo from transferring the code to the question or is that the way it is in your service?
Mike V Baker 13-Jul-18 8:40am View
   
In the In the 'What I have tried:' section you're supposed to put the code that you're trying and some note about what's going wrong.
Mike V Baker 12-Jul-18 10:36am View
   
Did you go back and remove the custom formatting from the data grid view column after you moved the formatting to the code behind side? If that's just a text type property and you don't have the custom format still in place to make the DGV think it's supposed to be a date then it shouldn't do any formatting at all.
Mike V Baker 8-Jul-18 23:55pm View
   
That's not enough. You need to post the view and the controller code for the particular page and where you're having a problem.
Mike V Baker 3-Jul-18 10:39am View
   
From the docs:
Returns:
An HtmlAgilityPack.HtmlNodeCollection containing a collection of nodes matching the HtmlAgilityPack.HtmlNode.XPath query, ***or null if no node matched*** the XPath expression.

Have you verified that your SelectNodes function should return as least some nodes? Verified the syntax of the search? Case sensitivity of the search criteria?
Since the doc says it can return null you should have a check if (inner != null) before you try to use it.
HTH, Mike
Mike V Baker 3-Jul-18 10:33am View
   
There's not enough information here to figure out what you mean. Which 'node' are you trying to remove? Do you actually want to remove it or just read it with code so you can do something with it. When you post 'what I have tried' we actually need to see the C# code that you're using in your attempts, not just the XML string again.
I'm happy to help resolve specific issues in logic or syntax errors, but with this information I can't tell where the ball park is.
Mike V Baker 2-Jul-18 11:26am View
   
You actually can write to a file so you could get strings.xml and write it to the phone's storage (you'll have to ask the user for storage permission). Then you can read in the xml, make changes and write it out.
You mentioned PHP. Is this PHP file running on a server someplace? You want to retrieve the value by calling the PHP file and then write it out to the xml? Perhaps local storage in a database might be more appropriate (secure). I would not suggest that you do this with your resources file. If you want to store a value that you read at runtime then create your own file or use a database.
Mike V Baker 27-Jun-18 9:24am View
   
Hi Eliza, I'm happy to hear you found a solution. Good luck with the rest of your project.
Mike V Baker 26-Jun-18 10:43am View
   
In this case (the column6 bit value) I would probably treat incoming 0 as 0, NULL as NULL, and anything else as 1
I have a question for you, this scheme to validate the incoming data... how do you record that some records didn't pass the validation? Is there an exception report with a TEXT field to contain the incoming raw data?
Mike V Baker 26-Jun-18 10:39am View
   
I think the thought there is that the other vendor's database might not be set up with those constraints so suneel is trying to verify the data first.
Mike V Baker 26-Jun-18 10:12am View
   
So you're saying that the PK in the AttendanceList table is the SN. Only the SN, no other fields are part of the Primary Key? This would mean that you can only have one record in the AttendanceList table for that student. The student cannot attend more than one class at a time, ever. Is this a transactional table where it's only used for a limited time and records are deleted when you're done with the process? If the PK is just the SN, then using a count to determine if there are multiple should never return > 1 because you can't insert two records with the same PK.
Mike V Baker 24-Jun-18 15:13pm View
   
Deleted
So you're saying that the PK in the AttendanceList table is the SN. Only the SN, no other fields are part of the Primary Key? This would mean that you can only have one record in the AttendanceList table for that student. The student cannot attend more than one class at a time, ever. Is this a transactional table where it's only used for a limited time and records are deleted when you're done with the process? If the PK is just the SN, then using a count to determine if there are multiple should never return > 1 because you can't insert two records with the same PK.
Mike V Baker 23-Jun-18 22:14pm View
   
So what you want for FulltimeTicket_Value is the number of fulltime jobs multiplied by the max vale? So if you have 5 records and the Vale is 2, 3, 5, 500, 6 then you want 2500, right? SUM * MAX or 5 * 500
Mike V Baker 23-Jun-18 14:00pm View
   
Thanks for the added information. I'm not sure it helped :) I'll try to concentrate just on the duplicate key part. One thing for certain, you cannot insert a record with the same PK as another record. It defeats the purpose of PRIMARY KEY. So what is the PK of the AttendanceList table? If it's the SN + the CourseId then you can only have one record for that student and that course.
What's an sNr? Does that play a part in the PK? Is the combination of those three things always a unique value?

At one point you said that the "else" checks to see if there's a duplicate key with the count. However that "else" stems from the if (Exist % 2 == 0) which is testing to see if you have an even number of records. What if there are records in that table for other courses? It doesn't appear to include all the values it would need for the PK so it might not be ruling out some records that it should.

I just noticed one more thing. In the 'insert' side you're setting departed=0 and attending=1. In the 'update' side you're setting departed=1 but you're not setting attending=0. Will attending always be 1 once they have attended at lease once?
Mike V Baker 22-Jun-18 16:52pm View
   
It says "See inner exception for details". What's in the inner exception?
Mike V Baker 22-Jun-18 14:16pm View
   
Since your database is on a remote server should we assume that there will be multiple clients using it? That opens up another possible issue.. when one client is online and another is offline. Client A might be updating while client B is offline and client B won't have any knowledge of the updates made by A when it comes back.
Mike V Baker 22-Jun-18 14:02pm View
   
It looks like there's a possibility in your logic where a record can exist but still fail the test. Look at this:
SqlCommand checkData = new SqlCommand("SELECT COUNT(dateArrival) FROM AttendanceList WHERE SN = @Id and Attending=0", cn);

Your criteria here is SN = @Id *AND* Attending=0. So if Attending doesn't equal 0 it won't be returned. I'm guessing that your primary key is just the SN so there you are. You're going to try to insert a new record with an SN that's already there. I'm not sure about the use of modulo.
if (Exist %2 == 0)
So you're checking to see if the number of records is an even number? Also... now that I think about it, I don't see anything here about a particular class. There's a student, and attendance... where's the specification in your query about what class is being attended? I see CourseId in the insert query but I don't see it used in the check to find a previous entry.

You mentioned in the intro that this data was connected to a data grid. But the names of the controls suggest individual controls, not rows and columns in a grid.
Mike V Baker 16-Jun-18 18:49pm View
   
If I understand you right you're taking the ID from a control, the imagecontrol. I'm not sure I understand the logic here. The ID of a control has nothing to do with values in the database. The control's ID is there only so that the C# codebehind can uniquely identify each control in the form. Things like comboBox1, comboBox2, imageControl1, etc (BTW I always suggest they be named by what they contain, cbUserNames).
What I have always done in this case is to store the actual URL that you want displayed in the database. Not necessarily the BLOB object, the actual data of the image, but the URL. Storing BLOB objects in the DB makes them more transportable, you can move the DB to another platform and not worry about having to also move the images. Still I usually store the URL.
I have never done any imagery as you describe here, a tree structure with X,Y coords. Not in a web form. Absolute positioning, relative to other objects, in different browsers... ever seen the old movie called "The Money Pit" ??
Mike V Baker 16-Jun-18 18:09pm View
   
Open your database in SSMS (Sql Server Management Studio). Right-click on the SP and choose 'Execute Stored Procedure'. Fill in the values in the dialogue as you would pass them in from the program and click 'OK'. The messages window will tell you wants wrong. One thing for certain, that you already suspect. You must have an Apt_id that already exists in the Apartment table. - assuming that's a FOREIGN KEY REFERENCES Apartments(Apt_id)
Mike V Baker 16-Jun-18 17:28pm View
   
Your Rent table has the foreign key lease_id that references the Lease table. I see that you're getting the rent_id from SCOPE_INDENTITY(). This isn't working because you're passing in 0 for the lease_id so the reference fails and doesn't insert the rent record. That's why it can't select the SCOPE_IDENTITY() (or the @@IDENTITY).
BTW - can interactively test a stored procedure in MS Sql Server Management Studio. Right click on the SP and choose to execute. Put in the values you're passing in from the program and run it. You'll see error messages in the Messages window.
Mike V Baker 16-Jun-18 8:57am View
   
So you're only trying to avoid repeating the "do something at the end of a group" code? I can't think of any way to avoid that. Of course if it's more than one or two lines I would write it up in a function and call that function so there's not a lot of duplication. Other than that something like that wouldn't keep me up at night.
What was it that you're trying to do with this code? If you're counting the cars per person then perhaps in the sql would be better..

SELECT FirstName, COUNT(CarType) FROM PeopleCars GROUP BY FirstName

Naturally in a real world app this info wouldn't be in a single table. The 'PeopleCars' here in this sample would more likely be a three table join.

Mike