TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
ricardo rosa
NA
20
0
How to retrieve data from SQl
Feb 23 2010 8:30 AM
Hi guys
I'm new in the business and i need to create a web service that receive 5 input fields, executes a store procedure and retrieve data from sql(strings and ints).
Can somebody show me the code because i have many errors hapening with my code.
My code is
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
namespace APPRECWS
{
/// <summary>
/// Summary description for Service1.
/// </summary>
public class AplicationRecordWS : System.Web.Services.WebService
{
public AplicationRecordWS()
{
//CODEGEN: This call is required by the ASP.NET Web Services Designer
InitializeComponent();
}
#region Component Designer generated code
//Required by the Web Services Designer
private IContainer components = null;
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
#endregion
// WEB SERVICE EXAMPLE
// The HelloWorld() example service returns the string Hello World
// To build, uncomment the following lines then save and build the project
// To test this web service, press F5
//
[WebMethod]
//
public string HelloWorld()
//
{
//
return "Hello World";
//
}
[WebMethod]
public GetDataResult[] GetData(SearchInformation InputData)
{
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
SqlCommand cmd = new SqlCommand("spFAWebServiceWC",conn);
conn.Open();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@BusinessSeg",InputData.BusinessSeg);
cmd.Parameters.Add("@BusinessBan",InputData.BusinessBan);
cmd.Parameters.Add("@BusinessType",InputData.BusinessType);
cmd.Parameters.Add("@ApplicatioName",InputData.ApplicatioName);
cmd.Parameters.Add("@ApplicationShortName",InputData.ApplicationShortName);
cmd.Parameters.Add("@RBS",InputData.RBS);
SqlDataReader dados = cmd.ExecuteReader();
//
Object [] values = new Object[dados.FieldCount];
//
int fieldCount = dados.GetValues(values);
//
ArrayList al = new ArrayList();
//
al.Add(values);
conn.Close();
while (dados.Read())
{
int ApplicationID=(int) dados["ApplicationID"];
int BusinessSeg=(int) dados["BusinessSeg"];;
int BusinessBan=(int) dados["BusinessBan"];;
string BusinessType=(string) dados["BusinessType"];;
string ApplicationName=(string) dados["ApplicationName"];;
string ApplicationShortName=(string) dados["ApplicationShortName"];;
string RBS=(string) dados["RBS"];;
string SystemType=(string) dados["SystemType"];;
string Status=(string) dados["Status"];;
}
//
GetDataResult[] resultado = new GetDataResult[fieldCount];
//
//
for(int x=0;x< dados;x++)
//
//
{
//
resultado[x] = new GetDataResult();
//
resultado[x].ApplicationID = (dados["ApplicationID"].ToString());
//
resultado[x].Business = dados.Rows[x]["Business"].ToString();
//
resultado[x].BusinessType = dados.Rows[x]["BusinessType"].ToString();
//
resultado[x].ApplicationName = dados.Rows[x]["ApplicationName"].ToString();
//
resultado[x].ApplicationShortName = dados.Rows[x]["ApplicationShortName"].ToString();
//
resultado[x].RBS = dados.Rows[x]["RBS"].ToString();
//
resultado[x].SystemType = dados.Rows[x]["SystemType"].ToString();
//
resultado[x].Status = dados.Rows[x]["Status"].ToString();
//
}
//
//
return resultado;
//
}
}
public class SearchInformation
{
public string BusinessSeg;
public string BusinessBan;
public string BusinessType;
public string ApplicatioName;
public string ApplicationShortName;
public string RBS;
}
public class GetDataResult
{
public int ApplicationID;
public int BusinessSeg;
public int BusinessBan;
public string BusinessType;
public string ApplicationName;
public string ApplicationShortName;
public string RBS;
public string SystemType;
public string Status;
}
}
}
Can anyone help me? Thanks a lot.
Reply
Answers (
7
)
How to publish a "local" website
Building Web 2.0 UIs with JSF, Realtime Updates with JSF and Ajax Push Taught at GIDS 2010