Showing posts with label public. Show all posts
Showing posts with label public. Show all posts

Friday, March 9, 2012

problem when insert DateTime to DataBase

the column type of stime and etime in Dabase both are datetime

------------------------------

public DateTime loginTime
{
get
{

//got user enter page's time
return DateTime.Now;
}

}

//record user's using time when user click exit button

protected void Button1_Click(object sender, EventArgs e)
{

int Member_No = Int32.Parse(cls_login2.GetCurrent_login_Member_no(this.Page));
int Lesson_No = Int32.Parse(Lesson_no);
int Prestep = 1;
string RemoteIp = Request.ServerVariables["REMOTE_ADDR"].ToString();

string sqlConn = "Insert into pro_Study_log (Member_no,Lesson_no,Study_log_stepid,Study_log_stime,Study_log_etime,Study_log_ip) ";
sqlConn += "values(" + Member_No + "," + Lesson_No + "," + Prestep + "," + loginTime + ", getdate(), '" + RemoteIp + "')";
SqlConnection connLog = new SqlConnection(StrConn);

SqlCommand cmdLog = new SqlCommand(sqlConn, connLog);
cmdLog.CommandType = CommandType.Text;
connLog.Open();
cmdLog.ExecuteNonQuery();
connLog.Close();

--------

and then I got error message on column Study_log_stime

I also trid set the dateimt tostring , still doesn't work..

I don't know where I did wrong... pleae help

many thanks

You need to put quotes around logintime. Also, I'd recommend using Parameterized Queries rather than concatenating strings. With what you have now there is a high potential for SQL Injection attacks.

|||

it's helpless if we just put quotes around logintime ( cause another error message)

problem has been resolved by use stored procedure...

thank you very much

Wednesday, March 7, 2012

Problem w/ Script Task accessing Directory Services

Using the example from SS online books:

The code is this:

Public Sub Main()

Dim directory As DirectoryServices.DirectorySearcher

Dim result As DirectoryServices.SearchResult

Dim email As String

email = Dts.Variables("email").Value.ToString

Try

directory = New _

DirectoryServices.DirectorySearcher("(mail=" & email & ")")

result = directory.FindOne

Dts.Variables("name").Value = _

result.Properties("name").ToString()

Dts.TaskResult = Dts.Results.Success

Catch ex As Exception

Dts.Events.FireError(0, _

"Script Task Example", _

ex.Message & ControlChars.CrLf & ex.StackTrace, _

String.Empty, 0)

Dts.TaskResult = Dts.Results.Failure

End Try

Dts.TaskResult = Dts.Results.Success

End Sub

End Class

My problem is I'm not getting a value for 'Name' instead when I display in a dataflow task (using dataviewer)following the script task the value of Name = 'System.DirectoryServices.ResultPropertyValueCollection'

It's seems like it is telling me its property not the value. I'm not a VB/.Net developer so I'm just guessing as to what the value means.

Any help would be appreciated.

thanks

I'm nod directory services expert, but from MSDN, the indexer of ResultPropertyCollection is declared as

Public ReadOnly Default Property Item ( _ name As String _ ) As ResultPropertyValueCollection

I.e. result.Properties("name") returns a collecions of properties, not the value.

|||

Found additional examples of how to do this and got it working

thanks

Monday, February 20, 2012

Problem using custom assemblies in SSRS2005

I've created a custom assembly (in VB (VS-2005)) for use in some SSRS2005
reports.
project: ReportsLibrary
Public Class ReportsCodeLibrary
Public Shared Function ReturnXML(MVList as Object, Root As String, Node As
String, Element As String) As String
Dim ReturnString = ""
Dim sParamItem As Object
ReturnString = "<" & Root & ">"
For Each sParamItem In MultiValueList
ReturnString &= "<" & Node & "><" & Element & ">" & sParamItem & "</"
& Element & "></" & Node & ">"
Next
ReturnString &= "</" & Root & ">"
Return (ReturnString)
End Function
Public Shared Function Format(s As String) As String
Format = left(s,4) & "-" & mid(s,5,2) & "-" & mid(s,7,3) & "-" &
right(s,4)
End Function
End Class
Each of these functions work properly if I put them in the Code section. But
since they are being used in multiple reports, I want to have the code in one
place and use that assembly.
The project is compiled in "Release" configuration.
I attach this compiled dll (ReportsLibrary.dll) to the report in the
Report's properties "Reference" section. Since these are Shared functions, I
don't need to define individual classes on that sheet.
When I get this working, I'll copy the dll to the SSRS ReportServer\bin
directory on the SSRS computer.
On the TextBox's (txtTableField2) Value property, I enter the expression
"=ReportsLibrary.ReportsCodeLibrary.Format(Fields!fieldName.Value)"
When I preview the report in Visual Studio, I get these errors:
[rsErrorLoadingCodeModule] Error while loading code module: â'ReportsLibrary,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=nullâ'. Details: Could not
load file or assembly 'ReportsLibrary, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null' or one of its dependencies. The system cannot find the
file specified.
[rsCompilerErrorInExpression] The Value expression for the textbox
â'txtTableField2â' contains an error: [BC30451] Name 'ReportsLibrary' is not
declared.
So, what am I missing? What do I need to do to get this assembly to work
with SSRS?
Thanks,
WayneIs the .dll copied to the following folder on your development machine:
"C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies"?
--
Matt
"Wayne" wrote:
> I've created a custom assembly (in VB (VS-2005)) for use in some SSRS2005
> reports.
> project: ReportsLibrary
> Public Class ReportsCodeLibrary
> Public Shared Function ReturnXML(MVList as Object, Root As String, Node As
> String, Element As String) As String
> Dim ReturnString = ""
> Dim sParamItem As Object
> ReturnString = "<" & Root & ">"
> For Each sParamItem In MultiValueList
> ReturnString &= "<" & Node & "><" & Element & ">" & sParamItem & "</"
> & Element & "></" & Node & ">"
> Next
> ReturnString &= "</" & Root & ">"
> Return (ReturnString)
> End Function
> Public Shared Function Format(s As String) As String
> Format = left(s,4) & "-" & mid(s,5,2) & "-" & mid(s,7,3) & "-" &
> right(s,4)
> End Function
> End Class
> Each of these functions work properly if I put them in the Code section. But
> since they are being used in multiple reports, I want to have the code in one
> place and use that assembly.
> The project is compiled in "Release" configuration.
> I attach this compiled dll (ReportsLibrary.dll) to the report in the
> Report's properties "Reference" section. Since these are Shared functions, I
> don't need to define individual classes on that sheet.
> When I get this working, I'll copy the dll to the SSRS ReportServer\bin
> directory on the SSRS computer.
> On the TextBox's (txtTableField2) Value property, I enter the expression
> "=ReportsLibrary.ReportsCodeLibrary.Format(Fields!fieldName.Value)"
> When I preview the report in Visual Studio, I get these errors:
> [rsErrorLoadingCodeModule] Error while loading code module: â'ReportsLibrary,
> Version=1.0.0.0, Culture=neutral, PublicKeyToken=nullâ'. Details: Could not
> load file or assembly 'ReportsLibrary, Version=1.0.0.0, Culture=neutral,
> PublicKeyToken=null' or one of its dependencies. The system cannot find the
> file specified.
> [rsCompilerErrorInExpression] The Value expression for the textbox
> â'txtTableField2â' contains an error: [BC30451] Name 'ReportsLibrary' is not
> declared.
> So, what am I missing? What do I need to do to get this assembly to work
> with SSRS?
> Thanks,
> Wayne|||Matt,
Thanks! this took care of it. If only I had found this documented somewhere...
"Matt" wrote:
> Is the .dll copied to the following folder on your development machine:
> "C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies"?
> --
> Matt
>
> "Wayne" wrote:
> > I've created a custom assembly (in VB (VS-2005)) for use in some SSRS2005
> > reports.
> >
> > project: ReportsLibrary
> > Public Class ReportsCodeLibrary
> > Public Shared Function ReturnXML(MVList as Object, Root As String, Node As
> > String, Element As String) As String
> > Dim ReturnString = ""
> > Dim sParamItem As Object
> > ReturnString = "<" & Root & ">"
> > For Each sParamItem In MultiValueList
> > ReturnString &= "<" & Node & "><" & Element & ">" & sParamItem & "</"
> > & Element & "></" & Node & ">"
> > Next
> > ReturnString &= "</" & Root & ">"
> > Return (ReturnString)
> > End Function
> >
> > Public Shared Function Format(s As String) As String
> > Format = left(s,4) & "-" & mid(s,5,2) & "-" & mid(s,7,3) & "-" &
> > right(s,4)
> > End Function
> > End Class
> >
> > Each of these functions work properly if I put them in the Code section. But
> > since they are being used in multiple reports, I want to have the code in one
> > place and use that assembly.
> >
> > The project is compiled in "Release" configuration.
> > I attach this compiled dll (ReportsLibrary.dll) to the report in the
> > Report's properties "Reference" section. Since these are Shared functions, I
> > don't need to define individual classes on that sheet.
> > When I get this working, I'll copy the dll to the SSRS ReportServer\bin
> > directory on the SSRS computer.
> >
> > On the TextBox's (txtTableField2) Value property, I enter the expression
> > "=ReportsLibrary.ReportsCodeLibrary.Format(Fields!fieldName.Value)"
> > When I preview the report in Visual Studio, I get these errors:
> > [rsErrorLoadingCodeModule] Error while loading code module: â'ReportsLibrary,
> > Version=1.0.0.0, Culture=neutral, PublicKeyToken=nullâ'. Details: Could not
> > load file or assembly 'ReportsLibrary, Version=1.0.0.0, Culture=neutral,
> > PublicKeyToken=null' or one of its dependencies. The system cannot find the
> > file specified.
> > [rsCompilerErrorInExpression] The Value expression for the textbox
> > â'txtTableField2â' contains an error: [BC30451] Name 'ReportsLibrary' is not
> > declared.
> >
> > So, what am I missing? What do I need to do to get this assembly to work
> > with SSRS?
> >
> > Thanks,
> > Wayne|||Hi Wayne,
You're right - I had to dig around in samples to find it. Difficult to
search on unless one knows to look for "Custom Report Item" in BOL.
Cheers,
Matt
"Wayne" wrote:
> Matt,
> Thanks! this took care of it. If only I had found this documented somewhere...
> "Matt" wrote:
> > Is the .dll copied to the following folder on your development machine:
> > "C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies"?
> > --
> > Matt
> >
> >
> > "Wayne" wrote:
> >
> > > I've created a custom assembly (in VB (VS-2005)) for use in some SSRS2005
> > > reports.
> > >
> > > project: ReportsLibrary
> > > Public Class ReportsCodeLibrary
> > > Public Shared Function ReturnXML(MVList as Object, Root As String, Node As
> > > String, Element As String) As String
> > > Dim ReturnString = ""
> > > Dim sParamItem As Object
> > > ReturnString = "<" & Root & ">"
> > > For Each sParamItem In MultiValueList
> > > ReturnString &= "<" & Node & "><" & Element & ">" & sParamItem & "</"
> > > & Element & "></" & Node & ">"
> > > Next
> > > ReturnString &= "</" & Root & ">"
> > > Return (ReturnString)
> > > End Function
> > >
> > > Public Shared Function Format(s As String) As String
> > > Format = left(s,4) & "-" & mid(s,5,2) & "-" & mid(s,7,3) & "-" &
> > > right(s,4)
> > > End Function
> > > End Class
> > >
> > > Each of these functions work properly if I put them in the Code section. But
> > > since they are being used in multiple reports, I want to have the code in one
> > > place and use that assembly.
> > >
> > > The project is compiled in "Release" configuration.
> > > I attach this compiled dll (ReportsLibrary.dll) to the report in the
> > > Report's properties "Reference" section. Since these are Shared functions, I
> > > don't need to define individual classes on that sheet.
> > > When I get this working, I'll copy the dll to the SSRS ReportServer\bin
> > > directory on the SSRS computer.
> > >
> > > On the TextBox's (txtTableField2) Value property, I enter the expression
> > > "=ReportsLibrary.ReportsCodeLibrary.Format(Fields!fieldName.Value)"
> > > When I preview the report in Visual Studio, I get these errors:
> > > [rsErrorLoadingCodeModule] Error while loading code module: â'ReportsLibrary,
> > > Version=1.0.0.0, Culture=neutral, PublicKeyToken=nullâ'. Details: Could not
> > > load file or assembly 'ReportsLibrary, Version=1.0.0.0, Culture=neutral,
> > > PublicKeyToken=null' or one of its dependencies. The system cannot find the
> > > file specified.
> > > [rsCompilerErrorInExpression] The Value expression for the textbox
> > > â'txtTableField2â' contains an error: [BC30451] Name 'ReportsLibrary' is not
> > > declared.
> > >
> > > So, what am I missing? What do I need to do to get this assembly to work
> > > with SSRS?
> > >
> > > Thanks,
> > > Wayne