Try to put the MainUtil.cs file under the folder of App-code, then the function in the class can be used without do any change.
Accoring to your code, I just change a little and can run very well in my VS:
public class MainUtil
{
public long ExecuteScarSQLResult(string SQLStatement)
{
int Myinteger = 0;
string connStr = "Data Source=localhost;Initial Catalog=testdatabase;Integrated Security=True";
SqlConnection con = new SqlConnection(connStr);
con.Open();
SqlCommand cmd = new SqlCommand(SQLStatement,con);
Myinteger = Convert.ToInt32(cmd.ExecuteScalar());
con.Close();
return Myinteger;
}
}
In the .aspx:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _11 : System.Web.UI.Page
{
MainUtil ss = new MainUtil();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click1(object sender, EventArgs e)
{
long ww = ss.ExecuteScarSQLResult("insert into aa values(1,'aa')");
Response.Write(ww);
}
}
Regards,
Amy Peng
Please mark the replies as answers if they help or unmark if not.
Feedback to us
I am very glad to do so. Please try to refer to the following code:
In the .class:
Public Class MainUtil
Public Function ExecuteScarSQLResult(SQLStatement As String) As Long
Dim Myinteger As Integer = 0
Dim connStr As String = "Data Source=localhost;Initial Catalog=testdatabase;Integrated Security=True"
Dim con As New SqlConnection(connStr)
con.Open()
Dim cmd As New SqlCommand(SQLStatement, con)
Myinteger = Convert.ToInt32(cmd.ExecuteScalar())
con.Close()
Return Myinteger
End Function
End Class
In the .cs:
Public Partial Class _11
Inherits System.Web.UI.Page
Private ss As New MainUtil()
Protected Sub Page_Load(sender As Object, e As EventArgs)
End Sub
Protected Sub Button1_Click1(sender As Object, e As EventArgs)
Dim ww As Long = ss.ExecuteScarSQLResult("insert into aa values(1,'aa')")
Response.Write(ww)
End Sub
End Class
inungh
Member
68 Points
183 Posts
NotImplementedException
Nov 19, 2012 03:43 AM|LINK
I created a new class call MainUtil which has some public Execute SQL function like following.
Public Class MainUtil
Public Function ExecuteScarSQLResult(ByRef SQLStatement As String) As Long
dim Myinteger as integer
Dim cmd As SqlCommand = New SqlCommand
Dim connStr As String = "Data Source=MyComputer\myServer;Initial Catalog=myDatabase;User ID=myID;Password=password"
Dim connection As New SqlConnection(connStr)
connection.Open()
With cmd
.CommandText() = SQLStatement
.CommandType = CommandType.Text
.Connection() = connection
Myinteger = Convert.ToInt32(.ExecuteScalar())
End With
connection.Close()
Return Myinteger
connection.Dispose()
End Function
Basically, I just need pass my SQL get a result.
I import the class in to my web form
Imports MyNameSpace.mainutil
I got NotImplementedException error message while I use the function of the new class .
Function ExecuteScarSQLResult(p1 As String) As Long
Throw New NotImplementedException
End Function
I see above function code in my module to be implement.
I would like to know what I need implement.
Should I call the function in the class?
Your help and informaiton is great appreciated,
regards,
Inungh,
Amy Peng - M...
Star
11650 Points
1082 Posts
Microsoft
Re: NotImplementedException
Nov 21, 2012 06:43 AM|LINK
Hi inungh,
Try to put the MainUtil.cs file under the folder of App-code, then the function in the class can be used without do any change.
Accoring to your code, I just change a little and can run very well in my VS:
public class MainUtil { public long ExecuteScarSQLResult(string SQLStatement) { int Myinteger = 0; string connStr = "Data Source=localhost;Initial Catalog=testdatabase;Integrated Security=True"; SqlConnection con = new SqlConnection(connStr); con.Open(); SqlCommand cmd = new SqlCommand(SQLStatement,con); Myinteger = Convert.ToInt32(cmd.ExecuteScalar()); con.Close(); return Myinteger; } }In the .aspx:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _11 : System.Web.UI.Page { MainUtil ss = new MainUtil(); protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click1(object sender, EventArgs e) { long ww = ss.ExecuteScarSQLResult("insert into aa values(1,'aa')"); Response.Write(ww); } }Regards,
Amy Peng
Feedback to us
Develop and promote your apps in Windows Store
inungh
Member
68 Points
183 Posts
Re: NotImplementedException
Nov 21, 2012 09:28 PM|LINK
Thanks for the mesage and help,
It is C# code which I am not familiar.
do you mind help me in VB code?
Thanks again for helping,
Regards,
Inungh,
Amy Peng - M...
Star
11650 Points
1082 Posts
Microsoft
Re: NotImplementedException
Nov 22, 2012 12:22 AM|LINK
Hi inungh,
I am very glad to do so. Please try to refer to the following code:
In the .class:
In the .cs:
Public Partial Class _11 Inherits System.Web.UI.Page Private ss As New MainUtil() Protected Sub Page_Load(sender As Object, e As EventArgs) End Sub Protected Sub Button1_Click1(sender As Object, e As EventArgs) Dim ww As Long = ss.ExecuteScarSQLResult("insert into aa values(1,'aa')") Response.Write(ww) End Sub End ClassI will recommand the tool for converting C# to VB: http://www.developerfusion.com/tools/convert/csharp-to-vb .
The tool for converting VB to C#: http://www.developerfusion.com/tools/convert/vb-to-csharp/ .
Thanks,
Amy Peng
Feedback to us
Develop and promote your apps in Windows Store
inungh
Member
68 Points
183 Posts
Re: NotImplementedException
Nov 22, 2012 01:13 AM|LINK
Thanks a million for the message and help and convert tools,
Regards,
Inungh,
Amy Peng - M...
Star
11650 Points
1082 Posts
Microsoft
Re: NotImplementedException
Nov 22, 2012 01:46 AM|LINK
Hi inungh,
It is my pleasure and I am very happy to help you!
Thanks,
Amy Peng
Feedback to us
Develop and promote your apps in Windows Store