顯示具有 Table 標籤的文章。 顯示所有文章
顯示具有 Table 標籤的文章。 顯示所有文章

2014年7月13日 星期日

[RESOLVED] Active Directory update


I have a process for users to update inofrmation in Ad, one of the things I never accounted for was last name change.  I am trying to change the CN but it keeps erroring me out and tried to search for information but have not been able to find anything. 
Does anyone know how to update the CN of an Active Directory account.  It does not like the remaning of the CN, others said this should work but does not seem to work for me.


Here is my code.


 


  myDataTable = New DataTable
myDataTable = getData(sql)

'Build the Cn
cn = myDataTable.Rows(0)(3).ToString() & "\, " & myDataTable.Rows(0)(17).ToString()

If myDataTable(0)(11) <> "" Then
phone = myDataTable(0)(11)
Else
phone = " "
End If

If myDataTable(0)(12) <> "" Then
ip = myDataTable(0)(12)
Else
ip = " "
End If

Try
user.Properties("employeeType").Value = myDataTable(0)(0).ToString()
user.Properties("mail").Value = myDataTable(0)(1).ToString()
user.Properties("displayName").Value = myDataTable(0)(2).ToString()
user.Properties("sn").Value = myDataTable(0)(3).ToString()
user.Properties("personalTitle").Value = myDataTable(0)(4).ToString()
user.Properties("title").Value = myDataTable(0)(5).ToString()
user.Properties("department").Value = myDataTable(0)(6).ToString()
user.Properties("l").Value = myDataTable(0)(7).ToString()
user.Properties("streetAddress").Value = myDataTable(0)(8).ToString()
user.Properties("st").Value = myDataTable(0)(9).ToString()
user.Properties("postalCode").Value = myDataTable(0)(10)
user.Properties("telephoneNumber").Value = phone.ToString()
user.Properties("ipPhone").Value = ip.ToString
user.Properties("physicalDeliveryOfficeName").Value = myDataTable.Rows(0)(13).ToString()
user.Properties("extensionAttribute2").Value = myDataTable.Rows(0)(14).ToString()
user.Properties("comment").Value = myDataTable.Rows(0)(15).ToString()
user.Properties("description").Value = myDataTable.Rows(0)(16).ToString()
user.CommitChanges()
'user.Rename("CN=" & cn)
'user.CommitChanges()

Return True
Catch ex As Exception
Return False
End Try

user.Close()
End If
dirEntry.Close()



I don't think you should need the domain here.  Assuming that column 17 is the user name then it would be:


User.Rename("CN=" + myDataTable.Rows(0)(17).ToString())






HI, that is not the domain, it is the last name and then I add some other data to it.  Here is the error I receive.


 


A device attached to the system is not functioning.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.DirectoryServices.DirectoryServicesCOMException: A device attached to the system is not functioning.


Source Error:
Line 320: user.Properties("description").Value = myDataTable.Rows(0)(16).ToString()
Line 321: user.CommitChanges()
Line 322: user.Rename("CN=" + cn)
Line 323: 'user.CommitChanges()
Line 324: ' End With

Source File: C:\inetpub\wwwroot\iMAC\App_Code\iMACAD.vb Line: 322

Stack Trace:


[DirectoryServicesCOMException (0x8007001f): A device attached to the system is not functioning.
]
System.DirectoryServices.DirectoryEntry.MoveTo(DirectoryEntry newParent, String newName) +335
System.DirectoryServices.DirectoryEntry.Rename(String newName) +44
iMACAD.UpdateADUser(String samAccount, Int32 userId) in C:\inetpub\wwwroot\iMAC\App_Code\iMACAD.vb:322
Admin_MacRequests.lnkSubmit_Click(Object sender, EventArgs e) in C:\inetpub\wwwroot\iMAC\Admin\MacRequests.aspx.vb:366
System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e) +116
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +101
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +9528578
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724




Oh....  I have pretty much the same code but I don't have the / in my names.  Perhaps you need to escape it: //  or try a different character.



HI I don't either I thought the / was the escape to get the comma puit in between last and first names.


Doe, John H MN NG FTS



Did you try without it?



found out i can conetacting and extra comma that i was not escaping in my datarow.  Guess I should hve checked the data before starting a fuss.


[RESOLVED] User Login????


i have four pages asp.net (c#)


(1) Login Page (2) MainMenu1   (3) MainMenu2 (4) MainMenu3


i also have sql database name "mydatabase" have three tables 


(1) Student (2) Teacher   (3) Admin


Login page contain 2 textboxes (  textbox1 for username,  textbox2 for password) and login button


i want when login button is pressed then check (match) username and password in three tables (Student ,Teacher ,Admin)


*if user is Student then page MainMenu1 is open


*if user is Teacher then page MainMenu2 is open


*if user is Admin then page MainMenu3 is open


plzzzzzz help me?????



Ok, post your code.  I think it would be nothing more than code behind visibility statements based on


if (!User.IsInRole == "Student") 
{
Menu1.Visibility = hidden;
}
else
{
Menu1.Visibility = visible;
}



At what stage are you?  Are you in the process of setting up the databases / tables? Or are you having to work with pre-existing tables?


Because if you are just starting, then the suggestion of bbcompent1 is a slick way to do it.  When each user is created, you would want a bit of code-behind to assign that user to one of the three Roles.


Then you probably only only need the tables that come with the asp.net membership, no need to add separate tables for the students, teachers, and admin.


And you only need one page for the menus -- not three -- just showing or hiding them as suggested.


[RESOLVED] How to write a code for LastLogin Date &amp; Time


Hi all, im doing a project that requires a LastLogin Date & Time that can be seen whenever a user logs on to the system. Currently im using manual codes. Can any1 guide me on codes to make it automatically detect lastlogin?


Below are my initial codes



Thanks



Hello ,


How you are maintaining a login ? i mean are you using any authentication techniques ?



If you are using aspnet membership table for user management and authenticate user then there is already "LastLoginDate" column in "aspnet_Membership" table. save that date in session before authenticate user and use that date. Afret authentication LastLoginDate
will be updated.


And if you are not using membership table then you have to create a table which cane store date and time of login.



Tthanks everyone for trying to help me with my problems. I've managed to seek help around and solved it !


[RESOLVED] How to set function for searching website content?


Hey friends when website has huge posts , contains , stuff so usually you see there is search box where user will type whatever they wanna search on website and according to his search , related contents use to display on page so how to do it ??



It depends where your site gets its data from.  If it is a sql server then use Free Text searching to search for text in your fields and show the results as neccessary.  You might also want to look into Lucene which is an indexing technology you can plug
into various things (including SQL Server I believe).  If your site is just text files or content in aspx files then you'll need something that can index your site and give you a search interface - google do products that do this, and there will be many others
that do this too.  There is no single answer to this, it depends how your site is constructed and where the data comes from.



Hi,


If the website contents is stored on a database, you will need to create a query that searches the fields of the tables that store the content that you want to search. Ex:




SELECT MyTable1.ContentId AS ContentID, MyTable1.Title AS ContentTitle
FROM MyTable1
WHERE MyTable1.MyFieldToSearch1 LIKE '%' + @MySearchString + '%'

UNION ALL

SELECT MyTable2.ContentId AS ContentID, MyTable2.Title AS ContentTitle
FROM MyTable2
WHERE MyTable2.MyFieldToSearch2 LIKE '%' + @MySearchString + '%'


UNION ALL

SELECT MyTable3.ContentId AS ContentID, MyTable3.Title AS ContentTitle
FROM MyTable3
WHERE MyTable3.MyFieldToSearch3 LIKE '%' + @MySearchString + '%'

...

Then you need to call this query either by placing it as StoredProcedure (if the database engine allows it.  MS SQL Server does, but MS Access doesn't, for instance) or by writing it on the codepage/class and calling it.



Hope this helps,



Obe



You can integrate google search for your website.



Hi,




SACHIN2708


Hey friends when website has huge posts , contains , stuff so usually you see there is search box where user will type whatever they wanna search on website and according to his search , related contents use to display on page so how to do it ??


As AidyF suggested depends on different factors. Apart from the suggestions from other members below are few articles that you might find useful:


" This article describes a simple, free, easy to install Search page written in C#. The goal is to build a simple search tool that can be installed simply by placing three files on a website, and that could be easily extended to add all the features
you might need for a local-site search engine.


There are two main parts to a Search engine:



  • the build process, which processes files, indexing their contents and creating the 'catalog'.
  • the search process, which uses the 'catalog' to find the search term and the names of the files it appears in.  "

Source Article -
http://www.codeproject.com/Articles/7579/Static-Site-Search-Engine-with-ASP-NET-C


Creating an ASP.NET Search Engine -
http://www.developerfusion.com/article/4389/create-a-site-search-engine-in-aspnet/


Adding a Search Method and Search View -http://www.asp.net/mvc/tutorials/mvc-5/introduction/adding-search (MVC App)


Hope you find the information useful!


Best Regards!



[RESOLVED] The data source does not support server-side data paging




When is AllowPaging ="False"  work fine!



Hello,


DataReaders doesn't support pagging, why ?DataReader is forward-only. Server-side Paging needs to be able to travel the datasource both backward and forward.So dont pass cmd.ExecuteReader directly to the datasource.Instead First load the reader
result to a datatable and then pass the datatable as datasource.


DataTable dt=new DataTable();
dt.Load(cmd.ExecuteReader());

gvBuyer.DataSource=dt;
gvBuyer.DataBind();

Hope This Helps.


[RESOLVED] How to do Update Profle page using , I am facing some problem please help.


Sir after login I come on profile page where information is showing like :


First Name: Sachin


Last Name : Agarwal


but it is not editable you can just see  and information is loading from database so now if you want to edit this information so I create one button Edit on same page when someone will click on edit button so new page will be open and I did coding in its
CS page in void Page_Load(object sender, EventArgs e)


  SqlConnection con = new SqlConnection(@"Data Source=USER-PC\SQLEXPRESS;Initial Catalog=Chitrakala;Integrated Security=True");

        con.Open();

        String id = Session["uname"].ToString();

        string query = ("select* from Artist where User_Name='" + id + "'");

        SqlCommand cmd = new SqlCommand(query, con);

        SqlDataAdapter adpt = new SqlDataAdapter(cmd);

        DataTable dt = new DataTable();

        adpt.Fill(dt);



        tb1.Text = dt.Rows[0]["First_Name"].ToString();

        tb2.Text = dt.Rows[0]["Last_Name"].ToString();

        con.Close();


in above coding Artist is my table name and First_Name" and Last_Name is field name in table so due to this coding when some one will click on edit button so information is loading in text box from database :


First Name: Sachin


Last Name : Agarwal


but now it is editable means if I want to change last name so I use backspace to remove Agarwal and write new name .


 now I created A save button on this page and on Save button I did this coding:


 SqlConnection con = new SqlConnection(@"Data Source=USER-PC\SQLEXPRESS;Initial Catalog=Chitrakala;Integrated Security=True");

        con.Open();

       

       String B = tb2.Text;

       String A = tb1.Text;

       

      string id= Session["uname"].ToString();





      string query = "update Artist set Last_name=('" + B + "') where User_Name='" + id + "'";



        SqlCommand cmd = new SqlCommand(query, con);

        cmd.ExecuteNonQuery();

        con.Close();



        Response.Redirect("Customer profile.aspx");


above query is update means after change it will redirect me to previous page means profile page but problem is Change is not done after click on Save button it is redirecting me on Profile page but no changes in Last name , still Agarwal is showing as Last
name so where is problem


Please help.



If you press ctrl+F5 do you see the updated information?



what ??? I am creating website and I am facing this error that Profile is not update please read full question my friend I need your help.



Hi,


According to your description and your code, first, the redirect did not redirect to Customer profile.aspx page, I suggest you check the path is correct. If the Customer profile.aspx page did not exist in the same level with profile.aspx page, please refer
to the code beow to redirect:


Response.Redirect("../Foloder/Customer profile.aspx");

Second I suggest you checking the updating, we should make sure the data in the DataBase, if the data in DataBase did not been updated, I suggest you making some break points to debug steps by steps. We should make sure the connections is connect right,
then we need check updating in the SQL database.


Third, after we redirect to Customer profile.aspx page, we should make sure we will bind new data to the page.


I searched an artical about update in profile, please refer to the link below:


http://asp-net-example.blogspot.com/2009/02/how-to-update-profile-in-aspnet.html


Hope it's useful for you.


Best Regards,


Michelle Ge


[RESOLVED] Fliter


i fliter gridview


using textbox and serach button


SP:



"SELECT * FROM [addproject1] WHERE ([ProjectName] LIKE '%' + @ProjectName + '%')">


but how write textbox to SP





sudharsan perumal



fliter gridview


using textbox and serach button


SP:



"SELECT * FROM [addproject1] WHERE ([ProjectName] LIKE '%' + @ProjectName + '%')">


but how write textbox to SP





Like this


string conString = ConfigurationManager.ConnectionStrings["MyCon"].ToString(); //Give your connection string here
SqlConnection sqlcon = new SqlConnection(conString);
SqlCommand sqlcmd;
SqlDataAdapter da;
DataTable dt = new DataTable();
String query;
if(txtsearch.Text!="")
query = "SELECT * FROM [addproject1] WHERE ([ProjectName] LIKE '%'" + txtsearch.Text + "%'";
}
sqlcmd = new SqlCommand(query, sqlcon);
sqlcon.Open();
da = new SqlDataAdapter(sqlcmd);
dt.Clear();
da.Fill(dt);
Gridview1.Source=dt;
GridView1.DataBind();


they come search button code?





sudharsan perumal


they come search button code?


Yes,you should write that code in the search button click event..query the database with the textbox value and bind your gridview.



Hi 


Create stored procedure:


CREATE PROCEDURE searchGrid
@ProjectName NVARCHAR(100)
AS
SELECT * FROM [addproject1] WHERE [ProjectName] LIKE '%' + @ProjectName + '%'

Codebehind: Write this on button click


string conString = ConfigurationManager.ConnectionStrings["MyCon"].ToString();
SqlConnection sqlcon = new SqlConnection(conString);
SqlCommand sqlcmd;
SqlDataAdapter da;
DataTable dt = new DataTable();
sqlcmd = new SqlCommand("searchGrid", sqlcon);
sqlcmd.CommandType = CommandType.StoredProcedure;
sqlcmd.Parameters.AddWithValue("@ProjectName", "ValueFromTextBox");
sqlcon.Open();
da = new SqlDataAdapter(sqlcmd);
dt.Clear();
da.Fill(dt);
Gridview1.Source=dt;
GridView1.DataBind();



protected void Button1_Click(object sender, EventArgs e)

{

SqlConnection con = new SqlConnection("Data Source=DASATML-PC;Initial Catalog=sudharsan;Integrated Security=True");

//String query;

if (TextBox14.Text != "")

{

SqlCommand cmd = new SqlCommand("SELECT * FROM [addproject1] WHERE ([ProjectName] LIKE '%'" + TextBox14.Text + "%'", con);

DataTable dt = new DataTable();


con.Open();

SqlDataAdapter da = new SqlDataAdapter(cmd);

con.Close();

dt.Clear();

da.Fill(dt);                                                                        ERROR:Incorrect syntax near 'java'.

Unclosed quotation mark after the character string        





GridView1.DataSource = dt;

GridView1.DataBind();

}

}


[RESOLVED] Finding a duplicate in a datatable, but excluding a row


How do I find a row in the datatable, and verified that the 'ID' is unique, but exclude the row that is being verified?


The Datatable in the code pulls all the rows, and it is finding all the rows for a duplicate ID. But I need it to exclude the row being verifity for that ID. How can I exclude it?




if (ID.Text != Dataset.Tables[0].Rows[0]["ID"].ToString())
{
string ID = "";
ID = ID.Text.ToString();

DataRow[] findrow = Datatable.Select("ID = '" + ID + "' ");

string findID = "";

foreach (DataRow row in findrow)
{
findID = row["ID"].ToString();
}

if (findID.ToString() == ID.ToString())
{
divError.Style.Add("visibility", "visible");
divError.Style.Add("display", "");
divError.Style.Add("top", "120%");
divError.Style.Add("left", "50%");
divError.Style.Add("margin-top", "-9em");
divError.Style.Add("margin-left", "-12em");
}

}



1. If its not possible to get distinct records, then get a new column which will have distinct value for each row e.g. autoincrement. This you can achieve in DB query or at code level. 


2. Get list of duplicates using LINQ and attached distinct value using min/max;


3. Use LINQ Outer join with step 2 output using distinct value as JOIN column




 


[RESOLVED] Active Directory update


I have a process for users to update inofrmation in Ad, one of the things I never accounted for was last name change.  I am trying to change the CN but it keeps erroring me out and tried to search for information but have not been able to find anything. 
Does anyone know how to update the CN of an Active Directory account.  It does not like the remaning of the CN, others said this should work but does not seem to work for me.


Here is my code.


 


  myDataTable = New DataTable
myDataTable = getData(sql)

'Build the Cn
cn = myDataTable.Rows(0)(3).ToString() & "\, " & myDataTable.Rows(0)(17).ToString()

If myDataTable(0)(11) <> "" Then
phone = myDataTable(0)(11)
Else
phone = " "
End If

If myDataTable(0)(12) <> "" Then
ip = myDataTable(0)(12)
Else
ip = " "
End If

Try
user.Properties("employeeType").Value = myDataTable(0)(0).ToString()
user.Properties("mail").Value = myDataTable(0)(1).ToString()
user.Properties("displayName").Value = myDataTable(0)(2).ToString()
user.Properties("sn").Value = myDataTable(0)(3).ToString()
user.Properties("personalTitle").Value = myDataTable(0)(4).ToString()
user.Properties("title").Value = myDataTable(0)(5).ToString()
user.Properties("department").Value = myDataTable(0)(6).ToString()
user.Properties("l").Value = myDataTable(0)(7).ToString()
user.Properties("streetAddress").Value = myDataTable(0)(8).ToString()
user.Properties("st").Value = myDataTable(0)(9).ToString()
user.Properties("postalCode").Value = myDataTable(0)(10)
user.Properties("telephoneNumber").Value = phone.ToString()
user.Properties("ipPhone").Value = ip.ToString
user.Properties("physicalDeliveryOfficeName").Value = myDataTable.Rows(0)(13).ToString()
user.Properties("extensionAttribute2").Value = myDataTable.Rows(0)(14).ToString()
user.Properties("comment").Value = myDataTable.Rows(0)(15).ToString()
user.Properties("description").Value = myDataTable.Rows(0)(16).ToString()
user.CommitChanges()
'user.Rename("CN=" & cn)
'user.CommitChanges()

Return True
Catch ex As Exception
Return False
End Try

user.Close()
End If
dirEntry.Close()



I don't think you should need the domain here.  Assuming that column 17 is the user name then it would be:


User.Rename("CN=" + myDataTable.Rows(0)(17).ToString())






HI, that is not the domain, it is the last name and then I add some other data to it.  Here is the error I receive.


 


A device attached to the system is not functioning.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.DirectoryServices.DirectoryServicesCOMException: A device attached to the system is not functioning.


Source Error:
Line 320: user.Properties("description").Value = myDataTable.Rows(0)(16).ToString()
Line 321: user.CommitChanges()
Line 322: user.Rename("CN=" + cn)
Line 323: 'user.CommitChanges()
Line 324: ' End With

Source File: C:\inetpub\wwwroot\iMAC\App_Code\iMACAD.vb Line: 322

Stack Trace:


[DirectoryServicesCOMException (0x8007001f): A device attached to the system is not functioning.
]
System.DirectoryServices.DirectoryEntry.MoveTo(DirectoryEntry newParent, String newName) +335
System.DirectoryServices.DirectoryEntry.Rename(String newName) +44
iMACAD.UpdateADUser(String samAccount, Int32 userId) in C:\inetpub\wwwroot\iMAC\App_Code\iMACAD.vb:322
Admin_MacRequests.lnkSubmit_Click(Object sender, EventArgs e) in C:\inetpub\wwwroot\iMAC\Admin\MacRequests.aspx.vb:366
System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e) +116
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +101
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +9528578
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724




Oh....  I have pretty much the same code but I don't have the / in my names.  Perhaps you need to escape it: //  or try a different character.



HI I don't either I thought the / was the escape to get the comma puit in between last and first names.


Doe, John H MN NG FTS



Did you try without it?



found out i can conetacting and extra comma that i was not escaping in my datarow.  Guess I should hve checked the data before starting a fuss.


[RESOLVED] User Login????


i have four pages asp.net (c#)


(1) Login Page (2) MainMenu1   (3) MainMenu2 (4) MainMenu3


i also have sql database name "mydatabase" have three tables 


(1) Student (2) Teacher   (3) Admin


Login page contain 2 textboxes (  textbox1 for username,  textbox2 for password) and login button


i want when login button is pressed then check (match) username and password in three tables (Student ,Teacher ,Admin)


*if user is Student then page MainMenu1 is open


*if user is Teacher then page MainMenu2 is open


*if user is Admin then page MainMenu3 is open


plzzzzzz help me?????



Ok, post your code.  I think it would be nothing more than code behind visibility statements based on


if (!User.IsInRole == "Student") 
{
Menu1.Visibility = hidden;
}
else
{
Menu1.Visibility = visible;
}



At what stage are you?  Are you in the process of setting up the databases / tables? Or are you having to work with pre-existing tables?


Because if you are just starting, then the suggestion of bbcompent1 is a slick way to do it.  When each user is created, you would want a bit of code-behind to assign that user to one of the three Roles.


Then you probably only only need the tables that come with the asp.net membership, no need to add separate tables for the students, teachers, and admin.


And you only need one page for the menus -- not three -- just showing or hiding them as suggested.


[RESOLVED] How to write a code for LastLogin Date &amp; Time


Hi all, im doing a project that requires a LastLogin Date & Time that can be seen whenever a user logs on to the system. Currently im using manual codes. Can any1 guide me on codes to make it automatically detect lastlogin?


Below are my initial codes



Thanks



Hello ,


How you are maintaining a login ? i mean are you using any authentication techniques ?



If you are using aspnet membership table for user management and authenticate user then there is already "LastLoginDate" column in "aspnet_Membership" table. save that date in session before authenticate user and use that date. Afret authentication LastLoginDate
will be updated.


And if you are not using membership table then you have to create a table which cane store date and time of login.



Tthanks everyone for trying to help me with my problems. I've managed to seek help around and solved it !


[RESOLVED] How to set function for searching website content?


Hey friends when website has huge posts , contains , stuff so usually you see there is search box where user will type whatever they wanna search on website and according to his search , related contents use to display on page so how to do it ??



It depends where your site gets its data from.  If it is a sql server then use Free Text searching to search for text in your fields and show the results as neccessary.  You might also want to look into Lucene which is an indexing technology you can plug
into various things (including SQL Server I believe).  If your site is just text files or content in aspx files then you'll need something that can index your site and give you a search interface - google do products that do this, and there will be many others
that do this too.  There is no single answer to this, it depends how your site is constructed and where the data comes from.



Hi,


If the website contents is stored on a database, you will need to create a query that searches the fields of the tables that store the content that you want to search. Ex:




SELECT MyTable1.ContentId AS ContentID, MyTable1.Title AS ContentTitle
FROM MyTable1
WHERE MyTable1.MyFieldToSearch1 LIKE '%' + @MySearchString + '%'

UNION ALL

SELECT MyTable2.ContentId AS ContentID, MyTable2.Title AS ContentTitle
FROM MyTable2
WHERE MyTable2.MyFieldToSearch2 LIKE '%' + @MySearchString + '%'


UNION ALL

SELECT MyTable3.ContentId AS ContentID, MyTable3.Title AS ContentTitle
FROM MyTable3
WHERE MyTable3.MyFieldToSearch3 LIKE '%' + @MySearchString + '%'

...

Then you need to call this query either by placing it as StoredProcedure (if the database engine allows it.  MS SQL Server does, but MS Access doesn't, for instance) or by writing it on the codepage/class and calling it.



Hope this helps,



Obe



You can integrate google search for your website.



Hi,




SACHIN2708


Hey friends when website has huge posts , contains , stuff so usually you see there is search box where user will type whatever they wanna search on website and according to his search , related contents use to display on page so how to do it ??


As AidyF suggested depends on different factors. Apart from the suggestions from other members below are few articles that you might find useful:


" This article describes a simple, free, easy to install Search page written in C#. The goal is to build a simple search tool that can be installed simply by placing three files on a website, and that could be easily extended to add all the features
you might need for a local-site search engine.


There are two main parts to a Search engine:



  • the build process, which processes files, indexing their contents and creating the 'catalog'.
  • the search process, which uses the 'catalog' to find the search term and the names of the files it appears in.  "

Source Article -
http://www.codeproject.com/Articles/7579/Static-Site-Search-Engine-with-ASP-NET-C


Creating an ASP.NET Search Engine -
http://www.developerfusion.com/article/4389/create-a-site-search-engine-in-aspnet/


Adding a Search Method and Search View -http://www.asp.net/mvc/tutorials/mvc-5/introduction/adding-search (MVC App)


Hope you find the information useful!


Best Regards!



[RESOLVED] The data source does not support server-side data paging




When is AllowPaging ="False"  work fine!



Hello,


DataReaders doesn't support pagging, why ?DataReader is forward-only. Server-side Paging needs to be able to travel the datasource both backward and forward.So dont pass cmd.ExecuteReader directly to the datasource.Instead First load the reader
result to a datatable and then pass the datatable as datasource.


DataTable dt=new DataTable();
dt.Load(cmd.ExecuteReader());

gvBuyer.DataSource=dt;
gvBuyer.DataBind();

Hope This Helps.


[RESOLVED] How to do Update Profle page using , I am facing some problem please help.


Sir after login I come on profile page where information is showing like :


First Name: Sachin


Last Name : Agarwal


but it is not editable you can just see  and information is loading from database so now if you want to edit this information so I create one button Edit on same page when someone will click on edit button so new page will be open and I did coding in its
CS page in void Page_Load(object sender, EventArgs e)


  SqlConnection con = new SqlConnection(@"Data Source=USER-PC\SQLEXPRESS;Initial Catalog=Chitrakala;Integrated Security=True");

        con.Open();

        String id = Session["uname"].ToString();

        string query = ("select* from Artist where User_Name='" + id + "'");

        SqlCommand cmd = new SqlCommand(query, con);

        SqlDataAdapter adpt = new SqlDataAdapter(cmd);

        DataTable dt = new DataTable();

        adpt.Fill(dt);



        tb1.Text = dt.Rows[0]["First_Name"].ToString();

        tb2.Text = dt.Rows[0]["Last_Name"].ToString();

        con.Close();


in above coding Artist is my table name and First_Name" and Last_Name is field name in table so due to this coding when some one will click on edit button so information is loading in text box from database :


First Name: Sachin


Last Name : Agarwal


but now it is editable means if I want to change last name so I use backspace to remove Agarwal and write new name .


 now I created A save button on this page and on Save button I did this coding:


 SqlConnection con = new SqlConnection(@"Data Source=USER-PC\SQLEXPRESS;Initial Catalog=Chitrakala;Integrated Security=True");

        con.Open();

       

       String B = tb2.Text;

       String A = tb1.Text;

       

      string id= Session["uname"].ToString();





      string query = "update Artist set Last_name=('" + B + "') where User_Name='" + id + "'";



        SqlCommand cmd = new SqlCommand(query, con);

        cmd.ExecuteNonQuery();

        con.Close();



        Response.Redirect("Customer profile.aspx");


above query is update means after change it will redirect me to previous page means profile page but problem is Change is not done after click on Save button it is redirecting me on Profile page but no changes in Last name , still Agarwal is showing as Last
name so where is problem


Please help.



If you press ctrl+F5 do you see the updated information?



what ??? I am creating website and I am facing this error that Profile is not update please read full question my friend I need your help.



Hi,


According to your description and your code, first, the redirect did not redirect to Customer profile.aspx page, I suggest you check the path is correct. If the Customer profile.aspx page did not exist in the same level with profile.aspx page, please refer
to the code beow to redirect:


Response.Redirect("../Foloder/Customer profile.aspx");

Second I suggest you checking the updating, we should make sure the data in the DataBase, if the data in DataBase did not been updated, I suggest you making some break points to debug steps by steps. We should make sure the connections is connect right,
then we need check updating in the SQL database.


Third, after we redirect to Customer profile.aspx page, we should make sure we will bind new data to the page.


I searched an artical about update in profile, please refer to the link below:


http://asp-net-example.blogspot.com/2009/02/how-to-update-profile-in-aspnet.html


Hope it's useful for you.


Best Regards,


Michelle Ge


[RESOLVED] Fliter


i fliter gridview


using textbox and serach button


SP:



"SELECT * FROM [addproject1] WHERE ([ProjectName] LIKE '%' + @ProjectName + '%')">


but how write textbox to SP





sudharsan perumal



fliter gridview


using textbox and serach button


SP:



"SELECT * FROM [addproject1] WHERE ([ProjectName] LIKE '%' + @ProjectName + '%')">


but how write textbox to SP





Like this


string conString = ConfigurationManager.ConnectionStrings["MyCon"].ToString(); //Give your connection string here
SqlConnection sqlcon = new SqlConnection(conString);
SqlCommand sqlcmd;
SqlDataAdapter da;
DataTable dt = new DataTable();
String query;
if(txtsearch.Text!="")
query = "SELECT * FROM [addproject1] WHERE ([ProjectName] LIKE '%'" + txtsearch.Text + "%'";
}
sqlcmd = new SqlCommand(query, sqlcon);
sqlcon.Open();
da = new SqlDataAdapter(sqlcmd);
dt.Clear();
da.Fill(dt);
Gridview1.Source=dt;
GridView1.DataBind();


they come search button code?





sudharsan perumal


they come search button code?


Yes,you should write that code in the search button click event..query the database with the textbox value and bind your gridview.



Hi 


Create stored procedure:


CREATE PROCEDURE searchGrid
@ProjectName NVARCHAR(100)
AS
SELECT * FROM [addproject1] WHERE [ProjectName] LIKE '%' + @ProjectName + '%'

Codebehind: Write this on button click


string conString = ConfigurationManager.ConnectionStrings["MyCon"].ToString();
SqlConnection sqlcon = new SqlConnection(conString);
SqlCommand sqlcmd;
SqlDataAdapter da;
DataTable dt = new DataTable();
sqlcmd = new SqlCommand("searchGrid", sqlcon);
sqlcmd.CommandType = CommandType.StoredProcedure;
sqlcmd.Parameters.AddWithValue("@ProjectName", "ValueFromTextBox");
sqlcon.Open();
da = new SqlDataAdapter(sqlcmd);
dt.Clear();
da.Fill(dt);
Gridview1.Source=dt;
GridView1.DataBind();



protected void Button1_Click(object sender, EventArgs e)

{

SqlConnection con = new SqlConnection("Data Source=DASATML-PC;Initial Catalog=sudharsan;Integrated Security=True");

//String query;

if (TextBox14.Text != "")

{

SqlCommand cmd = new SqlCommand("SELECT * FROM [addproject1] WHERE ([ProjectName] LIKE '%'" + TextBox14.Text + "%'", con);

DataTable dt = new DataTable();


con.Open();

SqlDataAdapter da = new SqlDataAdapter(cmd);

con.Close();

dt.Clear();

da.Fill(dt);                                                                        ERROR:Incorrect syntax near 'java'.

Unclosed quotation mark after the character string        





GridView1.DataSource = dt;

GridView1.DataBind();

}

}


[RESOLVED] Finding a duplicate in a datatable, but excluding a row


How do I find a row in the datatable, and verified that the 'ID' is unique, but exclude the row that is being verified?


The Datatable in the code pulls all the rows, and it is finding all the rows for a duplicate ID. But I need it to exclude the row being verifity for that ID. How can I exclude it?




if (ID.Text != Dataset.Tables[0].Rows[0]["ID"].ToString())
{
string ID = "";
ID = ID.Text.ToString();

DataRow[] findrow = Datatable.Select("ID = '" + ID + "' ");

string findID = "";

foreach (DataRow row in findrow)
{
findID = row["ID"].ToString();
}

if (findID.ToString() == ID.ToString())
{
divError.Style.Add("visibility", "visible");
divError.Style.Add("display", "");
divError.Style.Add("top", "120%");
divError.Style.Add("left", "50%");
divError.Style.Add("margin-top", "-9em");
divError.Style.Add("margin-left", "-12em");
}

}



1. If its not possible to get distinct records, then get a new column which will have distinct value for each row e.g. autoincrement. This you can achieve in DB query or at code level. 


2. Get list of duplicates using LINQ and attached distinct value using min/max;


3. Use LINQ Outer join with step 2 output using distinct value as JOIN column




 


[RESOLVED] Active Directory update


I have a process for users to update inofrmation in Ad, one of the things I never accounted for was last name change.  I am trying to change the CN but it keeps erroring me out and tried to search for information but have not been able to find anything. 
Does anyone know how to update the CN of an Active Directory account.  It does not like the remaning of the CN, others said this should work but does not seem to work for me.


Here is my code.


 


  myDataTable = New DataTable
myDataTable = getData(sql)

'Build the Cn
cn = myDataTable.Rows(0)(3).ToString() & "\, " & myDataTable.Rows(0)(17).ToString()

If myDataTable(0)(11) <> "" Then
phone = myDataTable(0)(11)
Else
phone = " "
End If

If myDataTable(0)(12) <> "" Then
ip = myDataTable(0)(12)
Else
ip = " "
End If

Try
user.Properties("employeeType").Value = myDataTable(0)(0).ToString()
user.Properties("mail").Value = myDataTable(0)(1).ToString()
user.Properties("displayName").Value = myDataTable(0)(2).ToString()
user.Properties("sn").Value = myDataTable(0)(3).ToString()
user.Properties("personalTitle").Value = myDataTable(0)(4).ToString()
user.Properties("title").Value = myDataTable(0)(5).ToString()
user.Properties("department").Value = myDataTable(0)(6).ToString()
user.Properties("l").Value = myDataTable(0)(7).ToString()
user.Properties("streetAddress").Value = myDataTable(0)(8).ToString()
user.Properties("st").Value = myDataTable(0)(9).ToString()
user.Properties("postalCode").Value = myDataTable(0)(10)
user.Properties("telephoneNumber").Value = phone.ToString()
user.Properties("ipPhone").Value = ip.ToString
user.Properties("physicalDeliveryOfficeName").Value = myDataTable.Rows(0)(13).ToString()
user.Properties("extensionAttribute2").Value = myDataTable.Rows(0)(14).ToString()
user.Properties("comment").Value = myDataTable.Rows(0)(15).ToString()
user.Properties("description").Value = myDataTable.Rows(0)(16).ToString()
user.CommitChanges()
'user.Rename("CN=" & cn)
'user.CommitChanges()

Return True
Catch ex As Exception
Return False
End Try

user.Close()
End If
dirEntry.Close()



I don't think you should need the domain here.  Assuming that column 17 is the user name then it would be:


User.Rename("CN=" + myDataTable.Rows(0)(17).ToString())






HI, that is not the domain, it is the last name and then I add some other data to it.  Here is the error I receive.


 


A device attached to the system is not functioning.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.DirectoryServices.DirectoryServicesCOMException: A device attached to the system is not functioning.


Source Error:
Line 320: user.Properties("description").Value = myDataTable.Rows(0)(16).ToString()
Line 321: user.CommitChanges()
Line 322: user.Rename("CN=" + cn)
Line 323: 'user.CommitChanges()
Line 324: ' End With

Source File: C:\inetpub\wwwroot\iMAC\App_Code\iMACAD.vb Line: 322

Stack Trace:


[DirectoryServicesCOMException (0x8007001f): A device attached to the system is not functioning.
]
System.DirectoryServices.DirectoryEntry.MoveTo(DirectoryEntry newParent, String newName) +335
System.DirectoryServices.DirectoryEntry.Rename(String newName) +44
iMACAD.UpdateADUser(String samAccount, Int32 userId) in C:\inetpub\wwwroot\iMAC\App_Code\iMACAD.vb:322
Admin_MacRequests.lnkSubmit_Click(Object sender, EventArgs e) in C:\inetpub\wwwroot\iMAC\Admin\MacRequests.aspx.vb:366
System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e) +116
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +101
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +9528578
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724




Oh....  I have pretty much the same code but I don't have the / in my names.  Perhaps you need to escape it: //  or try a different character.



HI I don't either I thought the / was the escape to get the comma puit in between last and first names.


Doe, John H MN NG FTS



Did you try without it?



found out i can conetacting and extra comma that i was not escaping in my datarow.  Guess I should hve checked the data before starting a fuss.


[RESOLVED] User Login????


i have four pages asp.net (c#)


(1) Login Page (2) MainMenu1   (3) MainMenu2 (4) MainMenu3


i also have sql database name "mydatabase" have three tables 


(1) Student (2) Teacher   (3) Admin


Login page contain 2 textboxes (  textbox1 for username,  textbox2 for password) and login button


i want when login button is pressed then check (match) username and password in three tables (Student ,Teacher ,Admin)


*if user is Student then page MainMenu1 is open


*if user is Teacher then page MainMenu2 is open


*if user is Admin then page MainMenu3 is open


plzzzzzz help me?????



Ok, post your code.  I think it would be nothing more than code behind visibility statements based on


if (!User.IsInRole == "Student") 
{
Menu1.Visibility = hidden;
}
else
{
Menu1.Visibility = visible;
}



At what stage are you?  Are you in the process of setting up the databases / tables? Or are you having to work with pre-existing tables?


Because if you are just starting, then the suggestion of bbcompent1 is a slick way to do it.  When each user is created, you would want a bit of code-behind to assign that user to one of the three Roles.


Then you probably only only need the tables that come with the asp.net membership, no need to add separate tables for the students, teachers, and admin.


And you only need one page for the menus -- not three -- just showing or hiding them as suggested.


[RESOLVED] How to write a code for LastLogin Date &amp; Time


Hi all, im doing a project that requires a LastLogin Date & Time that can be seen whenever a user logs on to the system. Currently im using manual codes. Can any1 guide me on codes to make it automatically detect lastlogin?


Below are my initial codes



Thanks



Hello ,


How you are maintaining a login ? i mean are you using any authentication techniques ?



If you are using aspnet membership table for user management and authenticate user then there is already "LastLoginDate" column in "aspnet_Membership" table. save that date in session before authenticate user and use that date. Afret authentication LastLoginDate
will be updated.


And if you are not using membership table then you have to create a table which cane store date and time of login.



Tthanks everyone for trying to help me with my problems. I've managed to seek help around and solved it !


[RESOLVED] How to set function for searching website content?


Hey friends when website has huge posts , contains , stuff so usually you see there is search box where user will type whatever they wanna search on website and according to his search , related contents use to display on page so how to do it ??



It depends where your site gets its data from.  If it is a sql server then use Free Text searching to search for text in your fields and show the results as neccessary.  You might also want to look into Lucene which is an indexing technology you can plug
into various things (including SQL Server I believe).  If your site is just text files or content in aspx files then you'll need something that can index your site and give you a search interface - google do products that do this, and there will be many others
that do this too.  There is no single answer to this, it depends how your site is constructed and where the data comes from.



Hi,


If the website contents is stored on a database, you will need to create a query that searches the fields of the tables that store the content that you want to search. Ex:




SELECT MyTable1.ContentId AS ContentID, MyTable1.Title AS ContentTitle
FROM MyTable1
WHERE MyTable1.MyFieldToSearch1 LIKE '%' + @MySearchString + '%'

UNION ALL

SELECT MyTable2.ContentId AS ContentID, MyTable2.Title AS ContentTitle
FROM MyTable2
WHERE MyTable2.MyFieldToSearch2 LIKE '%' + @MySearchString + '%'


UNION ALL

SELECT MyTable3.ContentId AS ContentID, MyTable3.Title AS ContentTitle
FROM MyTable3
WHERE MyTable3.MyFieldToSearch3 LIKE '%' + @MySearchString + '%'

...

Then you need to call this query either by placing it as StoredProcedure (if the database engine allows it.  MS SQL Server does, but MS Access doesn't, for instance) or by writing it on the codepage/class and calling it.



Hope this helps,



Obe



You can integrate google search for your website.



Hi,




SACHIN2708


Hey friends when website has huge posts , contains , stuff so usually you see there is search box where user will type whatever they wanna search on website and according to his search , related contents use to display on page so how to do it ??


As AidyF suggested depends on different factors. Apart from the suggestions from other members below are few articles that you might find useful:


" This article describes a simple, free, easy to install Search page written in C#. The goal is to build a simple search tool that can be installed simply by placing three files on a website, and that could be easily extended to add all the features
you might need for a local-site search engine.


There are two main parts to a Search engine:



  • the build process, which processes files, indexing their contents and creating the 'catalog'.
  • the search process, which uses the 'catalog' to find the search term and the names of the files it appears in.  "

Source Article -
http://www.codeproject.com/Articles/7579/Static-Site-Search-Engine-with-ASP-NET-C


Creating an ASP.NET Search Engine -
http://www.developerfusion.com/article/4389/create-a-site-search-engine-in-aspnet/


Adding a Search Method and Search View -http://www.asp.net/mvc/tutorials/mvc-5/introduction/adding-search (MVC App)


Hope you find the information useful!


Best Regards!