2. Open "Microsoft Visual Studio"
3. Click File -> Open -> Project/Solution
4. open file project On D:\Application\source\CLR\OCSCLR2
5. click Solution Explorer then right-click on project
6. then click Add -> New Item...
7. Add New Item dialog will open on visual Studio installed tamplates select "User-Defined Function" and then type function name on text box Name: and click button Add to create function
8. now you can modify code.
9. sample code
using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using System.IO;
using System.Net;
public partial class UserDefinedFunctions
{
[Microsoft.SqlServer.Server.SqlFunction]
public static SqlString MODIFYBALANCE(string msisdn,string amount,string remark)
{
string stringResult = "";
try
{
if (msisdn.StartsWith("856")) msisdn = msisdn.Substring(3);
string sms = "http://vas-service/ocs_..........";
string stringPost = "";// Request.Form.ToString();
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(sms);
httpWebRequest.Method = "POST";
httpWebRequest.KeepAlive = false;
httpWebRequest.ContentLength = stringPost.Length;
httpWebRequest.ContentType = "application/x-www-form-urlencoded";
StreamWriter streamWriter = null;
streamWriter = new StreamWriter(httpWebRequest.GetRequestStream());
streamWriter.Write(stringPost);
streamWriter.Close();
HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream()))
{
stringResult = streamReader.ReadToEnd();
streamReader.Close();
}
}
catch (Exception ex)
{
stringResult = ex.Message;
}
return new SqlString(stringResult);
}
};
No comments:
Post a Comment