0% found this document useful (0 votes)
228 views4 pages

MariaDB Stored Procedures for Employee Data

The document contains code for performing CRUD (create, read, update, delete) operations on a sample database table using stored procedures in SQL Server. Stored procedures are created to insert, update, delete and retrieve data from the table. C# code is provided to call each stored procedure by passing parameters and handle the database operations. A global connection string is also declared to connect to the database without needing to declare a new connection each time.

Uploaded by

sunilbabu29
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
228 views4 pages

MariaDB Stored Procedures for Employee Data

The document contains code for performing CRUD (create, read, update, delete) operations on a sample database table using stored procedures in SQL Server. Stored procedures are created to insert, update, delete and retrieve data from the table. C# code is provided to call each stored procedure by passing parameters and handle the database operations. A global connection string is also declared to connect to the database without needing to declare a new connection each time.

Uploaded by

sunilbabu29
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Stored procedure for

insert:

create procedure sample_ins(@empid int,@empname varchar(50),@empmobileno decimal(18,0),@empaddress varchar(max)) as begin insert into sample (empid,empname,empmobileno,empaddress)values(@empid,@empname, @empmobileno,@empaddress) end

Coding for insert button:


try { SqlCommand cmd=new SqlCommand ("sample_ins",con); [Link]=[Link]; [Link](); [Link]("empid",[Link]).Value=[Link]; [Link]("empname",[Link]).Value=TextBox2. Text; [Link]("empmobileno",[Link]). Value=[Link]; [Link]("empaddress",[Link]).Value=TextBo [Link]; [Link]("password", [Link]).Value = [Link]; [Link](); [Link](); //For clearing all the fields [Link] = ""; [Link] = ""; [Link] = ""; [Link] = ""; [Link] = ""; [Link]("Inserted Successfully...!"); } catch(Exception ex) { [Link]([Link]); } finally { [Link](); }

Stored procedure for Update:


create procedure sample_up(@empid int,@empmobileno decimal(18,0),@empaddress varchar(max),@password varchar(50)) as begin update sample set empmobileno=@empmobileno,empaddress=@empaddress,password= @password where empid=@empid end

Coding for Update button:


try { [Link](); SqlCommand Cmd = new SqlCommand("sample_up", con); [Link] = [Link]; [Link]("@empid", [Link]).Value = [Link]; [Link]("@empmobileno", [Link]).Value = [Link]; [Link]("@empaddress", [Link]).Value = [Link]; [Link]("@password", [Link]).Value = [Link]; [Link](); //For clearing all the fields [Link] [Link] [Link] [Link] [Link] = = = = = ""; ""; ""; ""; "";

[Link]("Updated Successfully...!"); } catch (Exception ex) { [Link]("[Link]"); } finally { [Link](); }

Stored procedure for Delete:


create procedure sample_del1 (@empid int) as begin delete from sample where empid=@empid end

Coding for Delete button:


[Link](); SqlCommand Cmd = new SqlCommand("sample_del1", con); [Link] = [Link]; [Link]("@empid",[Link]); [Link](); [Link](); //For clearing all the fields [Link] [Link] [Link] [Link] [Link] = = = = = ""; ""; ""; ""; "";

[Link]("Deleted Successfully...!");

Stored procedure for

Retrieving Data:

create procedure login1(@empid int),@password varchar(20) as begin select * from sample where empid =@empid end

For Retrieving Data:


try { [Link](); SqlCommand cmd = new SqlCommand("login1", con); [Link] = [Link]; [Link]("@empid", [Link]).Value = [Link]; [Link]("@password", [Link]).Value = [Link]; SqlDataReader rdr = [Link](); if ([Link]()) { [Link]("[Link]"); } else { [Link]("Employee id was incorrect"); } } catch (Exception ex) { [Link]([Link]); }

For Connection String:


SqlConnection con=new SqlConnection("Server=SYS18;Initial Catalog=NorthWind;Integrated Security=true;Database='suneel'");

Declare the connection string in the global of the class Then we need not to declare for all the operations NOTE: In the name space import the below string
using [Link];

You might also like