|
Looks like a reasonable update-statement, and looks like a sproc. I assume that it creates the procedure correctly, or did you get an error?
If the proc is correct, you hook it up to a SqlCommand and set the parameters. You'll probably already have something similar in the insert-statement.
The only thing that bugs a bit is the DateTime that seems to be used as a primary key. I suggest using an identity-field, an auto-incrementing integer. See, the dob might contain a specific time, and that would make it "hard" to find it in the database - a mismatch of a second, and it'll say the record can't be found.
paddymega wrote: I just want that the query matches the data in the databse to the data being passed on from the program and update it in the database
Programming is not an easy task; we're already skipping corners here
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
|
paddymega wrote: Shows error near ) , god knows what error.
If it "shows", then besides God, you could know too what it says. God would speak of a syntax-error here;
CREATE PROCEDURE EDITROW (INT naim, INT aig, INT fmno, INT doab)//these are the parameters being received by the program to the procedure
@age INT,//parameters from the database no wonwards
@name VARCHAR(30),
@familymemno INT,
@DOB int,//end of parameters from the database
AS
UPDATE elecdb
SET naim=@name, aig=@age, fmno=@fammemno, doab=@dob
WHERE @DOB=doab; //update query
RETURN
Are @age, @name etc. part of the parameter-list? If yes, then they should be declared before the ) mark. If not, then they should be declared in the body of the stored procedure, below the "AS" keyword. Something like this probably;
CREATE PROCEDURE EDITROW (INT @naim, INT @aig, INT @fmno, INT @doab)
AS
BEGIN
UPDATE elecdb // this is not a comment, this style will create a syntax error too!
SET name=@naim,
age=@aig,
fammemno = @fmno,
dob = @doab
WHERE dob = @doab;
END
The parameters in the UPDATE statement (the ones with the @-sign) need to match those at the top; the other names are the fieldnames, as defined in the elecdb-table.
I'm at home, on a Linux-laptop. I could open the archive, but there's no Sql Server to run it against.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Oh yes, u're right . My bad :P
The // was added for you guys only, so that the logic could be better viewable for u.
ps: The error's still there. The error is "incorrect syntax near INT, must declare the scalar variable @naim"
|
|
|
|
|
paddymega wrote: The error is "incorrect syntax near INT, must declare the scalar variable @naim"
You could look up the syntax in the documentation[^]. I'm guessing that the parameters need to be declared like in the documentation; the example I gave was not tested, and according to the docs, the parametername should precede the type, like this;
CREATE PROCEDURE EDITROW (@naim INT, @aig INT, @fmno INT, @doab INT)
AS
BEGIN
UPDATE elecdb
SET name=@naim,
age=@aig,
fammemno = @fmno,
dob = @doab
WHERE dob = @doab;
END
If you have more errors, feel free to post them; but please include your actual version of the code, and the error-message; that way you'll get the most (useful) replies.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
|
You're welcome
|
|
|
|
|
Tutorial[^]
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
I want to know how to show message from window serviece
|
|
|
|
|
Windows services do not display messages. At all.
A service is something that runs before the user even logs on; that means that there is no user to view your message, and no desktop to display it. The service even runs under a different account; open "Services" from the Admin-section in the config-panel, find your service, look at the second or third tab; that's where the username/password is specified for the account that the service is running under.
The default approach is to create a second app that runs under the users' credential, and have it communicate with the service. I'd recommend TCP/IP for that, but there are more ways to communicate.
Main question here is whether you actually "need" a service. So, what does your service do, and how would a "message" look like?
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
ashjassi wrote: show message
If you mean show a messagebox, you don't. Services do not interact with users by design.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Please stand in front of my pistol, smile and wait for the flash - JSOP 2012
|
|
|
|
|
As already stated, a Windows Service is designed to run in the background without a UI and is best suited for tasks that do not need user interaction or even a user session. If at all you have to show a message and interact with the user, you may consider writing a windows application instead of a windows service.
|
|
|
|
|
Windows Service dn't show message. if you show message you can write LOg FIle or you store message to DB
Vijay
|
|
|
|
|
Hello, am new to C# programming, and would like to develop a small application with an in-built scheduler which would for example daily wake up my PC from sleep mode at 8AM and go to sleep mode at 10PM, the same routine going on the next day from Mon to Fri every week.
I do know about using Task Scheduler in Windows 7, but here would like to do it programmatically using C#. Anyone can help me finding the exact codes to perform this?
Thx...
|
|
|
|
|
This[^] is an article that shows you how to put the computer into sleep mode.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Please stand in front of my pistol, smile and wait for the flash - JSOP 2012
|
|
|
|
|
lordrt wrote: I do know about using Task Scheduler in Windows 7,
The task manager is for starting applications; you could write an application that shuts the computer down, but waking it up is a lot more challenging.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
See here: Wake the PC from standby or hibernation[^] - it goes through the process and code pretty well.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
|
Hello,
I am trying to learn functions in C#. I wrote the following test functions and I am getting the error: Error 1 An object reference is required for the non-static field, method, or property 'Testing_Functions.Program.Test(double, double, double)' C:\Users\computerpublic\AppData\Local\Temporary Projects\Testing Functions\Program.cs 18 29 Testing Functions.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Testing_Functions
{
class Program
{
public Double Test(Double Val1, Double Val2, Double Val3)
{
Double Test_Val = Val1 + Val2 + Val3;
return Test_Val;
}
static void Main(string[] args)
{
Double A = 1, B = 2, C = 3;
Double Result = Test(A,B,C);
}
}
}
|
|
|
|
|
You have to declare the Test method as "static", just like your Main method.
Either that, you have to new up an instance of the Program class and use the Test method through that.
Serisouly, this is C# 101 stuff. You really need to pick up a beginners book on C# and work through it.
|
|
|
|
|
I am using the a book and I am following the example. I don't know why I am getting the error.
|
|
|
|
|
Look up the keyword "static", as that is why you are getting that particular error.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Please stand in front of my pistol, smile and wait for the flash - JSOP 2012
|
|
|
|
|
You're trying to call an instance method on an implicit this, but Main is static so there is no this.
|
|
|
|
|
The function "Main " is the start point of the program. When "Main " is called, no instance of any object could yet be created, hence it must be static .
From a static method, you can reach other static methods. Or you can create an object. When you create a e.g. new Windows Forms application in Visual Studio, it adds a line to Main : Application.Run(new Form1()); . This creates a new object of type Form1 .
Similarly, you could write another class, create the corresponding object, and call its function, e.g.
namespace Testing_Functions
{
class Addition
{
public Double Test(Double Val1, Double Val2, Double Val3)
{
Double Test_Val = Val1 + Val2 + Val3;
return Test_Val;
}
}
}
and then call it from your Main method:
Addition a = new Addition();
Double Result = a.Test(A,B,C);
|
|
|
|
|
I think it's been explained pretty well already, but just in case...
static methods are available without an instance of the class. Non static methods are only available through an instance of the class.
This gives you two options in your case. Either
1. Make the Test method static
public static Double Test(Double Val1, Double Val2, Double Val3)
or
2. Create a new instance of the class that holds the method (Program in this case).
Double Result = new Program().Test(A,B,C);
alternative
Program program = new Program();
Double Result = program.Test(A,B,C);
|
|
|
|
|