15,909,518 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by Member 10609511 (Top 27 by date)
Member 10609511
5-Mar-14 7:50am
View
Thank you this worked!! :)
Member 10609511
5-Mar-14 7:44am
View
I am getting no error in the C# code it runs properly without error and when I debug it the updated values from the textboxes are carried into the parameters it just isn't saving to the databsase
Member 10609511
26-Feb-14 15:55pm
View
Still no luck - when I used your c# code I got an error on:
comm1.ExecuteNonQuery();
-could not find the stored procedure
So I commented out this line of code and ran it again but still doesn't seem to save the updated textboxes from the webform in place of the original values....
Member 10609511
26-Feb-14 15:32pm
View
I have a solution that I have got working by incorporating this code with mine:
LinkButton l = e.CommandSource as LinkButton;
if(l != null)
{
GridViewRow selectedRow = l.NamingContainer as GridViewRow ;
if(selectedRow != null)
{
int intRowIndex = Convert.ToInt32(selectedRow.RowIndex);
}
}
Member 10609511
26-Feb-14 14:43pm
View
There Seems to be error in your code somewhere, the line:
string RowId = e.CommandArgument.["RowIndex"].ToString();
Gives the error: Identifier expected
Here is what I have in the asp code for gridview:
<itemtemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="false" CommandName="view" CommandArgument = ''<%#((GridViewRow)Container).RowIndex%>' + ';' + '<%#Eval("FileName")%>''>ViewFile
I found this elsewhere but not sure how to implement
ImageButton b = (ImageButton)sender;
GridViewRow row = (GridViewRow)b.NamingContainer;
if (row != null)
{
//Get the Row Index
int rowIndex = row.RowIndex;
//Get the DataKey value
string key = GridView1.DataKeys[rowIndex].Value.ToString();
//Get the Row value of BoundField
string rowValue = row.Cell[0].Text;
}
Member 10609511
26-Feb-14 13:55pm
View
The contents are the file name eg.123.jpg however I found a solution to the problem online but it seems to select only the first row(row index remains at 0)
int index;
bool bIsConverted = int.TryParse(e.CommandArgument.ToString(), out index);
Member 10609511
26-Feb-14 13:19pm
View
When I try that I get this error:
Input string was not in a correct format.
It is coming from the line
int i = Convert.ToInt32(e.CommandArgument);
When I run the debugger...
Member 10609511
26-Feb-14 12:04pm
View
I don't wish to select all the values from the entire row - just one value that is under the column heading 'Business Name' and has Datafield of 'Business_Name' in the gridview. This value will specifically depend on which row the user presses the link button 'View File' for that particular row. I then need to assign this value to a variable in my c# code...
Member 10609511
26-Feb-14 11:57am
View
I am getting error - object reference not set to an instance of an object. Basically depending on which row the users selects the link button 'view file' from I want to take the value of the cell in that row under column 'Business Name'
Member 10609511
25-Feb-14 12:44pm
View
I can't even upload video - when I insert a video file in the FileUpload control and hit the upload button I get a 'Page cannot be loaded' error
Member 10609511
25-Feb-14 12:34pm
View
sorry for the confusion - I just want to implement uploading and viewing of videos in what I already have, thanks
Member 10609511
25-Feb-14 8:46am
View
what would I change in the proc exactly?
Here is what I tried and still nothing:
WHERE T2.Username = @Username
AND T1.Business_ID=T2.Business_ID
Member 10609511
25-Feb-14 8:33am
View
No luck with that change - still not committing the changes from the textboxes to the database....
Member 10609511
24-Feb-14 21:28pm
View
This is a college project so I am still learning! Not to disrespect but you haven't been one bit helpful to me - hopefully someone will have a good input or solution to my question....
Member 10609511
24-Feb-14 21:25pm
View
I now have the updated textbox values being passed to the parameter in my c# code but when I am redirected back to business details page the updated details are not there so maybe there is a problem with updating two tables in my proc???
ALTER PROCEDURE dbo.SaveBusinessChanges
(
@Business_Name varchar(50),
@Address_Line_1 varchar(50),
@Address_Line_2 varchar(50),
@Address_Line_3 varchar(50),
@County varchar(50),
@Provence varchar(50),
@Telephone varchar(50),
@Username varchar(50),
@PasswordNew varchar(50),
@Email varchar(50)
)
AS
BEGIN TRANSACTION
UPDATE T1
SET T1.Business_Name = @Business_Name, Address_Line_1 = @Address_Line_1, Address_Line_2 = @Address_Line_2,
Address_Line_3 = @Address_Line_3, County = @County, Provence = @Provence, Telephone = @Telephone
FROM Business T1
INNER JOIN User_Acc T2 ON T1.Business_ID = T2.Business_ID
WHERE T2.Username = @Username
UPDATE
T2
SET
T2.Email = @Email, Password = @PasswordNew
FROM
User_Acc T2
INNER JOIN Business T1
ON
T2.Business_ID = T1.Business_ID
WHERE
T2.Username = @Username
COMMIT
Member 10609511
24-Feb-14 20:50pm
View
I have just told you where I got the listbox from - the toolbox in Visual Studio. It is an asp:Listbox item. It is not multi line. It is blank and you can add information to it using lstBusinessDetails.Items.Add. You're not really being helpful to me with your comments - maybe you could list out the types of list boxes and I'll understand your question better since it is a bit vague what you are requesting....
Member 10609511
24-Feb-14 20:39pm
View
I just dragged and dropped the listbox item from the toolbox in visual studio and the above code was generated from that
Member 10609511
24-Feb-14 20:27pm
View
Not quite sure what you mean??
<asp:TableRow ID="TableRow3" runat="server">
<asp:TableCell ID="TableCell5" runat="server" HorizontalAlign="Center" VerticalAlign="Top">Business :
<asp:TableCell ID="TableCell6" runat="server" HorizontalAlign="Left" VerticalAlign="Top"><asp:ListBox ID="lstBusinesses" runat="server" Width="245px" OnSelectedIndexChanged="ShowBusinessDetails" AutoPostBack="true">
<asp:TableRow ID="TableRow4" runat="server">
<asp:TableCell ID="TableCell12" runat="server" HorizontalAlign="Center" VerticalAlign="Top">Business Details :
<asp:TableCell ID="TableCell7" runat="server" HorizontalAlign="Left" VerticalAlign="Top"><asp:ListBox ID="lstBusinessDetails" runat="server" Width="256px">
Member 10609511
24-Feb-14 19:57pm
View
I have updated my code and it now runs - however when I make changes to any textboxes on the webpage and click the button to run the procedure, it doesn't take in the updated values but rather the values from the other data reader
protected void SaveChanges(object sender, EventArgs e)
{
SqlConnection conn;
SqlCommand comm;
String connectionString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
conn = new SqlConnection(connectionString);
comm = new SqlCommand("SELECT * from Business a, User_Acc c Where c.Username = @Username AND c.Business_ID = a.Business_ID", conn);
comm.Parameters.Add("@Username", System.Data.SqlDbType.VarChar).Value = Session["User"];
conn.Open();
SqlDataReader reader = comm.ExecuteReader();
while (reader.Read())
{
if (txtOldPassword.Text == reader["Password"].ToString())
{
// I'm not confortable using the same connection as the read - especially as we appear to
// be inside a reader loop so I'll create a new connection for the stored proc update
SqlConnection connWrite;
connWrite = new SqlConnection(connectionString);
// For info on the using statement see http://msdn.microsoft.com/en-us/library/htd05whh.aspx
using (SqlCommand comm1 = new SqlCommand("exec SaveBusinessChanges @Business_Name,@Address_Line_1,@Address_Line_2,@Address_Line_3,@County,@Provence,@Telephone,@Username,@PasswordNew,@Email", connWrite))
{
// Let the command know it is to run a Stored Procedure
comm1.CommandType = CommandType.StoredProcedure;
// This bit unchanged from OPs code
comm1.Parameters.AddWithValue("@Business_Name", txtChangeBusinessName.Text);
comm1.Parameters.AddWithValue("@Email", txtChangeBusinessEmail.Text);
comm1.Parameters.AddWithValue("@Telephone", txtChangeBusinessTelephone.Text);
comm1.Parameters.AddWithValue("@Address_Line_1", txtChangeBusinessAddress.Text);
comm1.Parameters.AddWithValue("@Address_Line_2", txtChangeBusinessAddress2.Text);
comm1.Parameters.AddWithValue("@Address_Line_3", txtChangeBusinessAddress3.Text);
comm1.Parameters.AddWithValue("@Provence", DDLProvince.Text);
comm1.Parameters.AddWithValue("@County", DDLCounty.Text);
comm1.Parameters.AddWithValue("@Username", Session["User"]);
comm1.Parameters.AddWithValue("@PasswordNew", txtChangeBusinessPassword.Text);
// You need to execute the command to run the stored procedure
comm1.ExecuteNonQuery();
} // Because I've used a "using" statement I don't need connWrite.Close();
}
}
reader.Close();
conn.Close();
Response.Redirect("Welcome.aspx");
}
}
Member 10609511
24-Feb-14 19:19pm
View
I have the error :
cannot implicitly convert type 'string' to 'bool'
here is the line of code
if (txtOldPassword.Text = reader["Password"].ToString())
Member 10609511
24-Feb-14 19:01pm
View
If I change txtChangeBusinessName.text to = rather than += I get an error :
cannot implicitly convert type 'object' to 'string'. an explicit conversion exists.
Member 10609511
24-Feb-14 10:52am
View
I have my procedure working however there is one field that was causing problems and I had to remove it. I have a table called Incident_Type and within this table there are 2 fields - Incident_ID(Int) and Incident_Type_Name(Varchar). However when I go to add this to my join and run my procedure I am getting the error - Multi-part Identifier cannot be bound and when I play around I also get an error saying cannot find Incident_Type.Incident_Type_Name even though it is spelt correctly
Here is my Proc:
ALTER PROCEDURE dbo.DisplayContent
(
@BusinessName varchar(100))
AS
SELECT user_acc.username, business.business_name, Incident.Incident_ID, Incident.File_Path, Incident.Description, Incident.Date_Time, Business.Provence, Business.County FROM
user_acc JOIN incident ON user_acc.User_id=incident.user_id
JOIN business ON incident.business_id=business.Business_id
WHERE Business.Business_Name = @BusinessName
RETURN
When I write it like this I get errors:
ALTER PROCEDURE dbo.DisplayContent
(
@BusinessName varchar(100))
AS
SELECT user_acc.username, business.business_name, Incident_Type.Incident_Type_Name, Incident.Incident_ID, Incident.File_Path, Incident.Description, Incident.Date_Time, Business.Provence, Business.County FROM
user_acc JOIN incident ON user_acc.User_id=incident.user_id
JOIN business ON incident.business_id=business.Business_id
WHERE Business.Business_Name = @BusinessName
RETURN
Member 10609511
21-Feb-14 16:15pm
View
It is still not working for me - I found an error however when I debugged the procedure. It seems for some reason that although I enter just one password into the txtOldPassword field it seems to double it when it is passed into the procedure??
Here is my Page Load code that fills the textboxes with data from the logged in user from the database.
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = "Welcome " + Session["User"];
lblUser.Text = Convert.ToString(Session["User"]);
SqlConnection conn;
SqlCommand comm;
String connectionString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
conn = new SqlConnection(connectionString);
comm = new SqlCommand("SELECT * from Business a, User_Acc c Where c.Username = @Username AND c.Business_ID = a.Business_ID", conn);
comm.Parameters.Add("@Username", System.Data.SqlDbType.VarChar).Value = Session["User"];
conn.Open();
SqlDataReader reader = comm.ExecuteReader();
while (reader.Read())
{
txtChangeBusinessName.Text += reader["Business_Name"];
txtChangeBusinessAddress.Text += reader["Address_Line_1"];
txtChangeBusinessAddress2.Text += reader["Address_Line_2"];
txtChangeBusinessAddress3.Text += reader["Address_Line_3"];
DDLProvince.SelectedItem.Text = "";
DDLCounty.SelectedItem.Text = "";
DDLProvince.SelectedItem.Text += reader["Provence"];
DDLCounty.SelectedItem.Text += reader["County"];
lblVatNo.Text += reader["Vat_No"];
txtChangeBusinessEmail.Text += reader["Email"];
txtChangeBusinessTelephone.Text += reader["Telephone"];
txtOldPassword.Text += reader["Password"];
txtChangeBusinessPassword.Text += reader["Password"];
}
reader.Close();
conn.Close();
}
Member 10609511
19-Feb-14 19:28pm
View
Does that help?
Member 10609511
19-Feb-14 19:15pm
View
I have some code written but it is not working fully. Here is what I have:
protected void UploadFile(object sender, EventArgs e)
{
if (btnBrowse.PostedFile != null && btnBrowse.PostedFile.ContentLength > 0)
{
string fileName = Path.GetFileName(btnBrowse.PostedFile.FileName);
string folder = Server.MapPath("~/BusinessProfilesContent/" + Session["BusinessName"]);
Directory.CreateDirectory(folder);
btnBrowse.PostedFile.SaveAs(Path.Combine(folder, fileName));
try
{
Response.Write("Uploaded: " + fileName);
}
catch
{
Label1.Text = "Operation Failed!!!";
}
}
}
protected void DownloadFile(object sender, EventArgs e)
{
string filePath = (sender as LinkButton).CommandArgument;
Response.ContentType = ContentType;
Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(filePath));
Response.WriteFile(filePath);
Response.End();
}
protected void DeleteFile(object sender, EventArgs e)
{
string filePath = (sender as LinkButton).CommandArgument;
File.Delete(filePath);
Response.Redirect(Request.Url.AbsoluteUri);
}
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = "Welcome " + Session["User"];
Session["BusinessName"] = lblBusiness.Text;
if (!IsPostBack)
{
string[] filePaths = Directory.GetFiles(Server.MapPath("~/BusinessProfilesContent/" + Session["BusinessName"]));
List<ListItem> files = new List<ListItem>();
foreach (string filePath in filePaths)
{
files.Add(new ListItem(Path.GetFileName(filePath), filePath));
}
GridView1.DataSource = files;
GridView1.DataBind();
}
Member 10609511
19-Feb-14 12:23pm
View
I got both select statements to work and return the data linked correctly as per your syntax, however, when I modify the procedure with your code it still is not making the changes to the database with the updated information from the textboxes
Here is the procedure code:
ALTER PROCEDURE dbo.SaveBusinessChanges
(
@Business_Name varchar(50),
@Address_Line_1 varchar(50),
@Address_Line_2 varchar(50),
@Address_Line_3 varchar(50),
@County varchar(50),
@Provence varchar(50),
@Telephone varchar(50),
@Username varchar(50),
@PasswordNew varchar(50),
@Email varchar(50)
)
AS
BEGIN TRANSACTION
UPDATE T1
SET T1.Business_Name = @Business_Name, Address_Line_1 = @Address_Line_1, Address_Line_2 = @Address_Line_2,
Address_Line_3 = @Address_Line_3, County = @County, Provence = @Provence, Telephone = @Telephone
FROM Business T1
INNER JOIN User_Acc T2 ON T1.Business_ID = T2.Business_ID
WHERE T2.Username = @Username
UPDATE
T2
SET
T2.Email = @Email, Password = @PasswordNew
FROM
User_Acc T2
INNER JOIN Business T1
ON
T2.Business_ID = T1.Business_ID
WHERE
T2.Username = @Username
COMMIT
and here is my C# code
protected void SaveChanges(object sender, EventArgs e)
{
SqlConnection conn;
SqlCommand comm;
SqlCommand comm1;
String connectionString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
conn = new SqlConnection(connectionString);
comm = new SqlCommand("SELECT * from Business a, User_Acc c Where c.Username = @Username AND c.Business_ID = a.Business_ID", conn);
comm.Parameters.Add("@Username", System.Data.SqlDbType.VarChar).Value = Session["User"];
conn.Open();
SqlDataReader reader = comm.ExecuteReader();
while (reader.Read())
{
if (txtOldPassword.Text.Equals(reader["Password"]))
{
comm1 = new SqlCommand("exec SaveBusinessChanges @Business_Name,@Address_Line_1,@Address_Line_2,@Address_Line_3,@County,@Provence,@Telephone,@Username,@PasswordNew,@Email", conn);
comm1.Parameters.AddWithValue("@Business_Name", txtChangeBusinessName.Text);
comm1.Parameters.AddWithValue("@Email", txtChangeBusinessEmail.Text);
comm1.Parameters.AddWithValue("@Telephone", txtChangeBusinessTelephone.Text);
comm1.Parameters.AddWithValue("@Address_Line_1", txtChangeBusinessAddress.Text);
comm1.Parameters.AddWithValue("@Address_Line_2", txtChangeBusinessAddress2.Text);
comm1.Parameters.AddWithValue("@Address_Line_3", txtChangeBusinessAddress3.Text);
comm1.Parameters.AddWithValue("@Provence", DDLProvince.Text);
comm1.Parameters.AddWithValue("@County", DDLCounty.Text);
comm1.Parameters.AddWithValue("@Username", Session["User"]);
comm1.Parameters.AddWithValue("@PasswordNew", txtChangeBusinessPassword.Text);
}
}
reader.Close();
conn.Close();
}
Member 10609511
19-Feb-14 11:53am
View
I don't get any error codes - I am calling the stored procedure from within Visual Studio 2010. It simply isn't updating any fields for that specific record in my database hence why I think there is something wrong with my procedure?
Show More