Oh, thanks for letting me know about that. I really should have looked over my message once it was posted. I'm not exatly sure what you mean by it isn't used, the SqlDataSource is called in DataSourceID of the dropdownlist. Or maybe I've misunderstood you. Thanks for the help! aqzman
aqzman_
Posts
-
Problem with scalar variable [modified] -
Problem with scalar variable [modified]Hey guys, I'm having a small problem with a scalar variable. I took the code from another project I wrote but there were a few changes in this new project so I wasn't able to do the same thing as last time. Anyway, now I'm getting the error "Must declare the scalar variable "@State".", mostly because I'm not exatly sure where to declare it. The code is a bit scattered, but I'll try to make it as short as I can, without leaving anything out. Although I think the problem is in the SqlDataSource with the select prameters / control parameter EDIT: In hindsight I really should have specified what I'm trying to do. There is a drop down list where users will pick a state of a variable from a database, then the infomation matching that state will be displayed accordingly. Drop Down List: The SqlDataSource: The VB/SQL code which would interact with the "@State": Dim cmd As New SqlCommand("SELECT * FROM tblTicket ... WHERE ... tblTicket.State = @State", New SqlConnection(strCon)) cmd.Connection.Open() Dim myReader As SqlDataReader = cmd.ExecuteReader() The actual error I was talking about ("Must declare the scalar variable "@State".") comes up at 'Dim myReader As SqlDataReader = cmd.ExecuteReader()', so I pretty much know that I just have the variable delared in the wrong place. I'd really appreciate any help, and if any more code is needed I'll post it right away. Thanks, aqzman
-
Datetime/Integer errorWorked like a charm, I knew it was only simple. I tried "+ & usrid & +" too, haha. Thanks a lot for the help!
-
Datetime/Integer errorHi guys, I'm having a pretty simple problem, but I guess I don't have the skill to solve it yet. I've wrote a string to get information from a database and put it into a label, all of that works fine but one of the fields is an Integer, and another is a datetime, so where I'm using "+"s it gives me an error, how can I solve this? Here is a shorted version of the line of code. txtMenu = txtMenu + "" + "" + " User's ID " + usrid + "" + "" + " State is " + State + "" + "" + " Date Opened was " + dateopen + "" + "" The HTML code is just for setting up a table, the error occurs between 'usrid' and 'dateopen', atleast, that's my best guess. Here is the exact error I get: "Operator '+' is not defined for types 'Double' and 'Date'.". Any suggestions would be a big help. Thanks, aqzman
-
Best way to go about displaying varchar(MAX) fields; GridviewThanks for both of your replies! I'll try your method, kubben.
-
Best way to go about displaying varchar(MAX) fields; GridviewHey guys, I don't really have a problem, I'm just looking for the best way to do something. I have an entry form where some information needs to be entered into a SQL database, but it's in a (Two of these fields, actually) Varchar(MAX) field. So the information entered could be one line, or a paragraph. There's really no way for me to know. I need to display several fields from three different databases into a gridview (that's already done) including the two varchar(MAX) fields. So my question is, what would be the best way to go about this? I know I could just let it all just display in the gridview as is, but that would probably really make things look untidy and unorganized if there were paragraph style enteries for all 10 records displaying on a page. Any suggestions would help. Thanks, aqzman
-
Extracting a single record from a SQL databaseThat worked like a charm! Thanks a lot for the help!
-
Extracting a single record from a SQL databaseHey guys, I'm having a little trouble with what I'm trying to do. I think there is just one or two lines of code that need to be entered (to what I already have), but I'm not exatly sure what it is. What I'm trying to do extract one record from a SQL database, because right now I have the SQL statement in a combobox with visable disabled, and I know that's not correct. Here is what I was thinking, and if this is totally wrong just let me know.
Sub Temp(ByVal myConnString As String) Dim mySelectQuery As String = "SELECT MAX(TicketID) AS Expr1 FROM tblTicket" Dim myConnection As New Data.SqlClient.SqlConnection(myConnString) Dim myCommand As New Data.SqlClient.SqlCommand(mySelectQuery, myConnection) myConnection.Open() Dim myReader As Data.SqlClient.SqlDataReader myReader = myCommand.ExecuteReader() myReader.Close() myConnection.Close() End Sub
The exact bit of data I want to extract is what would be in "Expr1". I've tried several different things, as in... Dim Number as Double ... Number = myReader... Hopefully there is just a few lines of code that can be entered to extract that data, if anyone can help me I'd really appreciate it. Thanks, aqzman
-
Gridview/DropDownList problem. Simple problem, I think [modified]Yup, I'll just throw everything on the working form. Thanks for the help!
-
Gridview/DropDownList problem. Simple problem, I think [modified]Thanks again for the reply. Well this is actually sort of strange, but good at the same time I guess. I made of copy of that page when it was working and it was saved in a folder, so I forgot about it. Anyway, that page is working fine, but the strangest thing is that I carried over all the code, and even checked the settings, they all match. One works, and the other doesn't. There is no value getting put into the @name on either page, the only time the actual phrase "@Name" is being used is in the selet query. Should I just write some code to assign the currently selected item in the drop down list to the @Name instead of just wondering how one page works? Haha. Thanks, aqzman
-
Gridview/DropDownList problem. Simple problem, I think [modified]Hi, thanks a lot for your reply! I never changed any code with the dropdownlist, and that's where I thought where the value was getting assigned to @Name. I just noticed that not all the code for the drop down list is getting displayed in my first post for some reason. Here is the drop down list code.
-
Gridview/DropDownList problem. Simple problem, I think [modified]Hey guys, I'm having a little problem with my drop down list and gridview. I used the drop down list to select what data is going to be shown in the gridview, it was working fine earlier but I changed the SQL string around a little bit and it went all haywire. Usually I back up my data every few hours, but just as my luck would have it, last time I backed up was right before I started that form. The error I'm getting is "Must declare the scalar variable "@Name".", but I thought it was declared, I must have a line left out in the drop down list settings. Here is the code that I think matters. If I'm leaving any out please let me know!
Thanks, aqzman Edit: Just thought this might help elimate some problems. When I run this code without the "AND tblUsers.Name = @Name" code the gridview and drop down list both fill up with all the data they need to, but obvisiouly none of the data in the gridview is filtered
-
Making datetime field null, SQLThanks a lot for your help! I really appreciate it.
-
Making datetime field null, SQLHi, Thanks a lot for the reply! I've actually tried the As New Nullable(Of DateTime) code before, but there's a problem with that in other parts of my code. One part is where I use a '+' symbol it says "Operator '+' is not defined for types 'System.Nullable(Of Date)'" and it also causes an error on my SQL insert statement which is "Operator '&' is not defined for types 'String' and 'System.Nullable(Of Date)'." I'm fairly new to VB.NET, SQL, and ASP.NET but those things seem to be almost totally unrelated as far as a nullable variable goes, guess not. Oh, and just to let you know, I am using the .NET 2.0 framework. Thanks again for the reply, aqzman
-
Making datetime field null, SQLHey guys, I have a question that I hope isn't too hard to get an anwser too, although even after all the Googling, and searching Code Project I've done I haven't had much luck yet. What I'm trying to do is make a Datetime field in a SQL database null (it's already set to allow nulls), but no matter how many different ways I try I either get an error or the default lowest time is just filled in (1900/01/01 12:00:00 AM). A time being there relys on the users input, so in some cases it might need to be filled in, in other cases it doesn't. Anyway, here is my code, if anymore is needed just ask!
Dim DateClosed As Date State = (ddlState.SelectedItem.Value) If State = 0 Then DateClosed = CDate(lstYear2.SelectedValue & "/" & lstMonth2.SelectedValue & "/" & lstDay2.SelectedValue) Time = " " & ddlHour2.SelectedItem.Value + ":" + ddlMin2.SelectedItem.Value + ddlAMPM2.SelectedItem.Value DateClosed += Time Else DateClosed = Nothing End If
Just incase anyone needs to know, State is a drop down box with two selections. Open or closed. Open = 1 and Closed = 0. Thanks, aqzman
-
SQL and VB.NET identity insert problem.Thanks a lot for the reply! I know my code might be a bit shakey, but I only started learning SQL, ASP.NET 2.0, and Visual Basic .NET last week. So sorry for any newbie mistakes, heh. Thanks for the advice about SQL Injection, I've only ever heard of it. Never read about it myself. This program will only be going up on a in-office intranet though, so I'm not too worried about attackers. But I'll probably fix it up once I read the links you posted. Never too early to start learning good programming habits. As for not including the column which will recieve the identity, that did the trick! Thanks a lot for your help! aqzman
-
SQL and VB.NET identity insert problem.Hi guys, I hope this is the right section, but as it's more of a SQL problem, it most likly is. Anyway, my problem is that I get this error: "DEFAULT or NULL are not allowed as explicit identity values." Everytime I try to run my code, but of all the searhing I've done on Google and Google code search I really can't find anything amiss. I'll post my source (What I think is needed) at the bottem. If there are any important lines of code that I've left out ask and I'll promptly post them.
Dim mySelectQuery As String = "SELECT \* FROM tblCallers SET IDENTITY\_INSERT tblCallers ON" Dim myInsertQuery As String = "INSERT INTO tblCallers (CallerID, Name, Address, PostalCode, City, PhoneNumber, EmailAddress) VALUES(DEFAULT, '" & Name & "', '" & Address & "', '" & PostalCode & "', '" & City & "', '" & PhoneNum & "', '" & EmailAddress & "')" Dim myConnection As New Data.SqlClient.SqlConnection(myConnString) Dim myCommand As New Data.SqlClient.SqlCommand(mySelectQuery, myConnection) Dim myCommand2 As New Data.SqlClient.SqlCommand(myInsertQuery, myConnection) Dim retvalue As Integer myConnection.Open() retvalue = myCommand2.ExecuteNonQuery() Console.WriteLine(retvalue) Dim myReader As Data.SqlClient.SqlDataReader myReader = myCommand.ExecuteReader() myReader.Close() myConnection.Close()
I know that the code works because I use took it from another program I wrote and added the "SET IDENTITY_INSERT tblCallers ON" line. Also, the CallerID field is an Identity field. Thanks, aqzman
-
Setting a column inside of a gridview to a linkIs this what you're talking about? http://image.bayimg.com/ia/dl/ia/ab/g.jpg Also, thanks for the reply!
-
Setting a column inside of a gridview to a linkHey guys! I've been Googling for about an hour now, and I can't seem to find any anwsers, hopefully someone here is able to help me. What I want to do is set text on a gridview as a link to a local harddrive. I've provided a link to a picture of what I've set up, and under the "Files" column is where I'd like the link to be, so users can just right click and "Save Target As..." to get the file. http://image.bayimg.com/ca/dl/ga/ab/g.jpg Thanks, aqzman
-
Date Time Picker (I searched already)That's great! Thanks a lot for your reply, and help!