Recordset Error While Filling The Listbox
Jun 9, 2004
Hello all
I have shifted my vb/access database to vb/mysql and i have one form in my project in which i want to display all the records in the database in the list box . But while doing this i m getting the error " variable uses an automation type not supported in visual basic " . Moreover, it was working in Vb/access .
here is the code
Dim sql As String
intCountSW_ID = 0
sql = "select SW_IDEN, SW_NAME, SW_DELETE,SW_LEFTDATE from SV_SOCIALWORKER order by SW_NAME"
If rs.State = 1 Then rs.Close
Set connString = New ADODB.Connection
connString.CursorLocation = adUseClient
connString.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};" _
& "SERVER=;" _
& "DATABASE=shrivatsa;" _
& "UID=root;" _
& "OPTION=" & 1 + 2 + 8 + 32 + 2048 + 16384
connString.Open
rs.ActiveConnection = connString
rs.CursorLocation = adUseClient
rs.Open sql, connString, adOpenStatic, adLockOptimistic
intCountSW_ID = rs.RecordCount
If intCountSW_ID > 0 Then
rs.MoveFirst
While Not rs.EOF
/* here comes the error on the below code
If rs("SW_DELETE") = 0 And IsNull(rs("SW_LEFTDATE"))
*/
Then
lstCaseName.AddItem rs("SW_IDEN") & " " & rs("SW_NAME")
End If
rs.MoveNext
Wend
rs.Close
End If
mfuncFillList = intCountSW_ID
View 1 Replies
ADVERTISEMENT
Jun 7, 2007
Hi All,
I'm hoping somebody can help me with this as it is driving me mad. I've created a stored procedure which returns Employee information recordset when the windows username is passed to it as a parameter. I want to then store this information in Session variables so content can be filtered depending on employee status, but when I execute my code no records are returned. I know for a fact that the stored procedure works because I bound it sqldatasource and displayed results from it in a Datalist and tested it in sql server. My code is as follows can anybody see any problems with it, in runs through fine with but when I try a read a field from the datareader in says there is no data to read.
Dim CurrentUser As String, Pos1 As Int16, EmployeeId As Int32
Dim cn As New System.Data.SqlClient.SqlConnection
Dim param As New System.Data.SqlClient.SqlParameter
Dim reader As System.Data.SqlClient.SqlDataReader
Dim cmd As New System.Data.SqlClient.SqlCommand
CurrentUser = CStr(User.Identity.Name)
Pos1 = InStr(CurrentUser, "") + 1
CurrentUser = Mid(CurrentUser, Pos1)
Session("User") = CurrentUser
Session("CID") = Nothing
cn.ConnectionString = "Data Source=LAPTOP-4SQLEXPRESS;Initial Catalog=SCMdb;Integrated Security=True"
cn.Open()
cmd.Connection = cn
cmd.CommandText = "CurrentUser"
cmd.CommandType = CommandType.StoredProcedure
param = cmd.CreateParameter
param.ParameterName = "@UserName"
param.SqlDbType = SqlDbType.VarChar
param.Value = CurrentUser
cmd.Parameters.Add(param)
reader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
EmployeeId = reader.Item("EmployeeID")
reader.Close()
Any help would be much appricated this is driving me mad.
Thank You
Shaft
View 5 Replies
View Related
Nov 15, 2006
Hi,
I always get a "ConstraintException" error when trying, at beginning of application, to run following statement (within "Form1_Load" routine called by "this->Load" EventHandler):
"this->TauxTaxeTableAdapter->FillByPays(this->TauxTaxeDataSet->TauxTaxe,Cur_GrdView_SlPays);"
Also curiously if, while application is still running, I invoke again that same statement by means of a pushbutton clickevent, everything is running smootly without error... Looks to me that it is bugging only when running the first time...
Within Dataset, I tried to see what constraint could give me such trouble. Here is the only constraint I could find:
"this->Constraints->Add((gcnew System::Data::UniqueConstraint(L"Constraint1", gcnew cli::array< System::Data::DataColumn^ >(2) {this->columnPays, this->columnProvince_Etat}, true)));"
I then tried to find within "TauxTaxe" table if there could be any trace of records where "Pays" and "Province_Etat" columns would show any null value as well as any duplicate key values but there wasn't any...
Any place I should start to look for? BTW, I'm using a SQL Express database.
Thanks for your help,
Stéphane
Here is the detailed error log I got:
System.Data.ConstraintException: Impossible d'activer les contraintes. Une ou plusieurs lignes contiennent des valeurs qui violent les contraintes de type non null, unique ou de clé externe.
à System.Data.DataSet.FailedEnableConstraints()
à System.Data.DataSet.EnableConstraints()
à System.Data.DataSet.set_EnforceConstraints(Boolean value)
à System.Data.Common.DataAdapter.Fill(DataTable[] dataTables, IDataReader dataReader, Int32 startRecord, Int32 maxRecords)
à System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
à System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
à System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
à Test_ADO.DS_TauxTaxeTableAdapters.TA_TauxTaxe.FillByPays(TauxTaxeDataTable dataTable, String Pays) dans d:projetvisual c++ 2005projets c++cli est_adods_tauxtaxe.h:ligne 1247
à Test_ADO.Form1.Sel_Pays_NewSel(Object sender, EventArgs e) dans d:projetvisual c++ 2005projets c++cli est_adoform1.h:ligne 1887
à System.Windows.Forms.RadioButton.OnCheckedChanged(EventArgs e)
à System.Windows.Forms.RadioButton.set_Checked(Boolean value)
à Test_ADO.Form1.Init_Form1() dans d:projetvisual c++ 2005projets c++cli est_adoform1.h:ligne 1480
à Test_ADO.Form1.Form1_Load(Object sender, EventArgs e) dans d:projetvisual c++ 2005projets c++cli est_adoform1.h:ligne 1446
à System.Windows.Forms.Form.OnLoad(EventArgs e)
à System.Windows.Forms.Form.OnCreateControl()
à System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
à System.Windows.Forms.Control.CreateControl()
à System.Windows.Forms.Control.WmShowWindow(Message& m)
à System.Windows.Forms.Control.WndProc(Message& m)
à System.Windows.Forms.ScrollableControl.WndProc(Message& m)
à System.Windows.Forms.ContainerControl.WndProc(Message& m)
à System.Windows.Forms.Form.WmShowWindow(Message& m)
à System.Windows.Forms.Form.WndProc(Message& m)
à System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
à System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
à System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Finally, SQL Statement for "TA_TauxTaxe::FillByPays" is the following:
SELECT Pays, Province_Etat, Taxe1_Appl, Taxe1_Dsc, Taxe1_Taux, Taxe2_Appl, Taxe2_Dsc, Taxe2_Taux
FROM TauxTaxe
WHERE (Pays = @Pays)
In debug mode, I double-checked and could verify that @Pays didn't have any null value but a valid string value at time "Fill" routine was invoked. Any clue?
View 3 Replies
View Related
Jan 4, 2007
When I run the code below, I get
a table with "In order to evaluate an indexed property, the property
must be qualified and the arguments must be explicitly supplied by the
user." as the contents...
Public Function ReturnTable(ByVal strName As String, ByVal alParameters As ArrayList, ByVal strTable As String) As DataSet
Dim sqlSP As New SqlCommand
sqlSP.CommandTimeout = 120
sqlSP.Connection = sqlConn
sqlSP.CommandType = CommandType.StoredProcedure
sqlSP.CommandText = strName
AddParameters(sqlSP.Parameters, alParameters)
Dim dsDataSet As New DataSet()
sqlConn.Open()
Dim sqlDataAdapter As New SqlDataAdapter(sqlSP)
sqlDataAdapter.Fill(dsDataSet, strTable)
sqlConn.Close()
Return dsDataSet
End Function
AddParameters is a function which adds each of the parameters in the
array list to the sqlSP parameter collection... In SQL Profiler, the sp
is called and runs and returns results... But a dataset with one table
and the above msg is returned...
View 2 Replies
View Related
Aug 13, 2004
I am trying to run the following asp function:
Private Function GetAbs(dThisDate, lPartID)
sql_abs = "SELECT AbsCode FROM Absence WHERE AbsDate = '" & dThisDate & "' AND PartID = " & lPartID
Set rs_abs = conn.Execute(sql_abs)
GetAbs = rs_abs(0).Value
Set rs_abs = Nothing
End Function
It works fine if it finds a record but returns an error if it doesn't. How can I avoid this error?
Thanks!
View 2 Replies
View Related
May 10, 2004
I know, I know this is really an ASP question but I'm thinking that you db gurus write some frontend code too. I have an ASP script (see snippet) that connects to my SQL Server 7 db (see connect string below).
16 sqlUser = "SELECT instructorId, schoolId, salutation, firstName, lastName, phone, email " & _
17 "FROM tblInstructors " & _
18 "WHERE (((userName)='"&Request.Form("userName")&"') AND ((password)='"&Request.Form("password")&"'))"
19
20 Set rsUser = Server.CreateObject("ADODB.RecordSet")
21 rsUser.Open sqlUser, oConn
This code runs fine as long as I key in a valid username and password. If I key in a bad username and password combo the db returns the following to my browser:
ADODB.Recordset error '800a0bb9'
Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
/loginProc.asp, line 21
I tested by writing the finished sql to my browser and pasting it into the Enterprise manager and it runs as expected, I get a record with valid credentials and no record otherwise (but no error).
I'm using SQL Server v7, can anyone shed any light on this? thanks
connect string:
"Provider=sqloledb;" & _
"Data Source=(local);" & _
"Initial Catalog=GradeTrax;" & _
"User ID=sa;" & _
"Password=pword"
View 10 Replies
View Related
Feb 9, 2007
Hi,
I am converting a VB6 application to C# using ADO. I have the following code:
private ADODB.Connection cn = new ADODB.Connection();
private ADODB.Recordset rs = new ADODB.Recordset();
private connectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data source= " + stdDir;
strClientSQL = "SELECT * FROM Client ORDER BY casename, renldate, product, fundingcode";
cn.CursorLocation = ADODB.CursorLocationEnum.adUseClient;
cn.Open(Utilities.connectionString,null,null,0);
rs.CursorLocation = ADODB.CursorLocationEnum.adUseServer;
rs.Open(strClientSQL,cn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic,-1);
rs.Fields["CaseName"].Value = this.txtCaseName.Text;
rs.Fields["CaseNo"].Value = this.txtCaseNumber.Text;
rs.Update();
When I try to compile and run it I get the following error message:
"No overload for method 'Update' takes '0' arguments"
I am not sure if I need to enter information in the update command or do something else. This seems pretty straight forward but I can't figure out how to do it. Can someone please help me?
Thanks,
Mark
View 4 Replies
View Related
Jul 23, 2005
Dear All,(No aswers on access newsgroups)Access2000.adp connected to SQL-server 2000MainForm unbound: seachform on companies meeting a complex combination ofcriteria.SubFrom and ListBox to display the searchresult ( 2 outputs to test what'sbest).Searchresult is stored in a creatable ADO-recordset (see code) and then1. Converted to string (GetString) to be set as valuelist for a listbox.2. bound to the subform.The Listbox shows the resultdata correctly but is limited in length.The subform shows the records but all fields are empty or displays #errorHow should I bound the controls correctly to display the fieldvalues?If I let them unbound the show up empty.If I set them to the recordsets' fieldnames it show #error.On my Notebook using MSDE there is no errormessageOn my Desktop i get error 7965 not a valid recordset property.CAN'T FIND WHAT'S WRONG! Cursortype ??FilipCODE'Store result in creatable ADO-recordset: Add fieldsWith ResultRSWith .Fields.Append "CompID", adInteger.Append "CompName", adVarChar, 255.Append "BasicPrice", adVarChar, 255End With.CursorLocation = adUseClient.CursorType = adOpenStatic.OpenEnd With[color=blue][color=green]>> Code for Search[/color][/color]'Set Rowsource Listbox and subformIf ResultRS.RecordCount > 0 ThenstrSearchResult = ResultRS.GetString(adClipString, , ";", ";")Me.Formulier1.Form.Visible = TrueSet Me.Formulier1.Form.Recordset = ResultRSMe.CmbSearchResult.Visible = TrueMe.CmbSearchResult.RowSource = strSearchResultEnd IfSearchEnd:'Clear memoryIf rs.State = adStateOpen Thenrs.CloseSet rs = NothingEnd IfIf ResultRS.State = adStateOpen ThenResultRS.CloseSet ResultRS = NothingEnd If
View 1 Replies
View Related
Feb 23, 2008
Hi,
I am using the following code
I use SQLOLEDB Provider
It is not stored porcedure but program code
create new global temporary table with
CREATE TABLE ##tmp123 (...
create and open a recorsset to populate it as direct table
at the open stage I get the following error: Invalid object name '##tmp123'
How can I get it working?
View 2 Replies
View Related
Jun 15, 2015
I am getting an error (number -2147217887, error message "ODBC--call failed.") when I try to execute an rst.Update. I have an MS Access 2013 application using an ODBC connection to SQL Server 2008 r2. I am using a query to update a table. It is a simple Select query with no joins. I have checked to make sure the table can be updated.
I was not sure if there were any special permissions that I need to set to allow a linked table to be updated in MS Access this way?
View 4 Replies
View Related
Oct 2, 2007
I have an update query in an OLE DB Destination (access mode: SQL Command) that updates a table with an INNER JOIN from another table in another database. I'm getting the error, "No disconnected recordset available for the specified SQL statement". Does this have to do with the SQL query trying to access the other database? How can I get around this error?
View 4 Replies
View Related
Aug 12, 2007
To anyone that can help me
we have a application written in straight ASP, we recently upgraded our SQL database connecting to the application from SQL 2000 to 2005 here is the issue
currently SQL 2005 is located in our test and UAT environments, SQL 2005 is not clustered in either location. Now let me make it clear THIS PROBLEM IS NOT HAPPENING IN OUR TEST ENVIRONMENT, I REPEAT THIS PROBLEM IS NOT HAPPENING IN OUR TEST ENVIROMENT, THIS PROBLEM IS ONLY HAPPENING IN OUR UAT ENVIROMENT
Each enviroment is outfitted with the following SQL 2005 environment, Enterprise Edition SP1 with Cumlative hotfix package 2153 just the SISS fix ONLY
now the problem is this, we have a vb program located directly on the server that has SQL 2005 on it that VB program inserts a timestamp into a table inside the database, now how this happens is the program connects to the database and opens a recordset with a forwardonly cursor and inserts the timestamp
NOW THE EXACT PROBLEM IS THAT THE VB PROGRAM CANNOT OPEN MULTIPLE RECORDSETS, THE ERROR RECEIVED IS LABLED LIKE THIS
ODBC DRIVER ERROR 8000405 SHARED MEMORY SQL DOESNT EXIST OR ACCESSED DENIED,
NOW here is the interesting part, AGAIN THIS IS NOT HAPPENING IN OUR TEST ENVIRONMENT, THE VB PROGRAM AGAIN IS ON THE TEST SQL SERVER AND HAS A FORWARD ONLY CURSOR AND INSERTS JUST FINE
NOW IF I MOVE THE VB PROGRAM OUT OF OUR UAT ENVIRONMENT ONTO ANOTHER SERVER IT INSERTS THE RECORD ONTO SQL SERVER JUST FINE, IT OPENS THE RECORDSET AND OPERATES NORMALLY, BOTH SERVERS HAVE EXACT SAME PERMISSIONS
Can anyone help me understand whats happening here
One note, when we changed the cursortype from forward-only to keyset it worked fine but that doesnt explain things
why does it work in test so clearly what we did with changing the cursortype isnt the answer
Thanks please consider this a urgent request
View 5 Replies
View Related
Apr 30, 2007
I am wandering how to "Properly do this" Without doing a dynamic SP. How do I do a search with the multiple listbox data. What do I pass the stored procedure?
SELECT ID, LAST_NAME || ', ' || FIRST_NAME AS FULLNAMEFROM BIT_USER1WHERE (TYPE_ID = 1) OR (TYPE_ID = 3) OR (TYPE_ID = 4) OR (TYPE_ID = 5) OR (BLDG_ID = 1) OR (BLDG_ID = 2)ORDER BY LAST_NAME, FIRST_NAME
View 4 Replies
View Related
Nov 12, 2007
Hi. I want to use a FilterExpression in my sqldatasource that verify if a value is in a listbox with several values. How can I do that? Thanks
View 3 Replies
View Related
Feb 10, 2004
Sorry if this is to basic but I am just starting out. Any help is appreciated.
Basically I am attempting to populate a listbox with items from a MSSQL DB so the user can select either one or multiple items in that listbox to search on.
View 1 Replies
View Related
Jun 20, 2007
Hi everyone, having some problems
Basically, using ASP.NET 2.0 and here is my problem,
Get data from table
Put into array
Split where there is a +
remove +'s
assign to listbox to give a list of everything in that table
The + split the courses, so in my Order table I have A + B + C etc and I want all of the different options in a list box (note different records have different entries it isn't always a b c)
I am testing my code, here is what I got
Public Sub TitleChange(ByVal Sender As Object, ByVal E As EventArgs) Try Dim DBConn As SqlConnection Dim DSPageData As DataSet = New DataSet() Dim VarTxtAOE As String DBConn = New SqlConnection("Server=SD02;Initial Catalog=WhoGetsWhat;Persist Security Info=True;UID=x;Password=XXX") 'Dim DBDataAdapter As SqlDataAdapter DBDataAdapter = New SqlDataAdapter("Select AOE FROM TBL_Role WHERE Title = @ddlTitle", DBConn) DBDataAdapter.SelectCommand.Parameters.Add("@ddlTitle", SqlDbType.NVarChar) DBDataAdapter.SelectCommand.Parameters("@ddlTitle").Value = TitleDropDown.SelectedValue DBDataAdapter.Fill(DSPageData, "Courses") 'Need to find out what this rows business is about whats the number about? and am I doing it correct? 'txtAOE.Text = DSPageData.Tables("Courses").Rows(0).Item("AOE") 'txtAOE.Items.Add(New ListItem(DSPageData.Tables(0).Rows(0).Item("AOE"))) VarTxtAOE = DSPageData.Tables("Courses").Rows(0).Item("AOE") Dim VarArray() As String = VarTxtAOE.Split("+") Response.Write(VarArray()) txtAOE.DataSource = VarArray() txtAOE.DataBind() 'Response.Write(test) 'ListBox1.DataSource = test 'Response.Write(VarArray) Catch TheException As Exception lblerror.Text = "Error occurred: " & TheException.ToString() End Try End Sub My response.Write works correctly, but my list box doesn't, also I don't want to say which bit of the array like I have done using 1, I just want to display the whole array in my list box. I am not worrying about removing the +'s at the minute, just splitting my data and putting each section into a listbox
Maybe I am going about this the wrong way, but I have been trying a lot of different things and its hard to find any help
Thanks
Chris
View 9 Replies
View Related
Aug 30, 2005
I need to use the list of items from a multiselect listbox in a parameter of a query's IN clause.
Example:
I assemble the list from the listbox and set the paramter value so @CityList = 'London','Paris','Rome' .... etc.
A sample SQL would be:
SELECT * FROM Customers
WHERE City IN (@CityList)
However, the SQL will not work. It seems the whole string is put in
another set of single quotes by the compiler so it's treated as one
string literal instead of a list.
Is there a way around this?
View 4 Replies
View Related
Dec 1, 2005
Hi. With VWD i've produced the following code.<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:50469ConnectionString %>"SelectCommand="SELECT * FROM [ibs] WHERE ([liedID] = @liedID)"><SelectParameters><asp:ControlParameter ControlID="ListBox1" Name="liedID" PropertyName="SelectedValue" Type="Int16" />But the query is only returning one row of the table. Even when multiple values were selected in the ListBox1. Could someone tell me how to do?Thanks, Kin Wei.
View 2 Replies
View Related
Apr 23, 2008
Hi There,
I am having a 1st listbox which is populating production lines, 2nd combobox to populate the production units. From here , the user will be able to select multiple production units from the combobox and hence populate the variable in listbox 3.
This is the query that I'm using to query on the variable table:
'SELECT DISTINCT PU_Id,Var_Id,Var_Desc from Variables
where PU_Id IN (@ProductionUnits)'
The problem now is that this would return all the variables for the selected production units and for those variables that have the same name, they would appear in the listbox as duplicates.
I wonder if there's any way to filter off or remove the duplicates in the listbox 3 by using sql query?
Thanks in advance for the help.
ksyong17
View 9 Replies
View Related
Nov 1, 2004
Hello All
I am wanting to fill a drop down list in ASP.NET using C# from a SQL database table using a stored procedure. I have my Sproc. But using ASP.NET C# I have no idea how to do this. Can someone give me a good example, and if not too much trouble, place comments in the code, and give an explanation. I am just learning ASP.NET after moving from Classic. Things are alot different.
Thank You in advnace for all your help
Andrew
View 1 Replies
View Related
Mar 21, 2008
I have a ton of data to load into a SQL 2005 database.
I just loaded a bunch of data for a number of tables using bcp, and the last table that my script loaded was an 8 million row table. The next table was a 12 million row table, and about 1 million rows into the bcp'ing a log full error was incurred. I have the batch size set to 10000 for all bcp commnads.
Here is the bcp command that failed:
"C:Program FilesMicrosoft SQL Server80ToolsBinncp" billing_data_repository..mtr_rdng_hrly_arc_t in mtr_rdng_hrly_arc_t.dat -c
-b10000 -Sxxxx -T
Here is the last part of the output from the bcp command:
...
10000 rows sent to SQL Server. Total sent: 970000
10000 rows sent to SQL Server. Total sent: 980000
10000 rows sent to SQL Server. Total sent: 990000
SQLState = 37000, NativeError = 9002
Error = [Microsoft][ODBC SQL Server Driver][SQL Server]The transaction log for database 'billing_data_repository' is full. To find out why space in the log cannot be reused, see the log_reuse_wait_desc column in sys.databases
BCP copy in failed
I thought that a commit was issued after every 10000 rows and that this would keep the log from filling up.
The log_reuse_wait_desc column in sys.databases is set to 'LOG_BACKUP' for the database being used.
Does a checkpoint need to be done more often?
Besides breaking up the 12 million row data file into something more manageable, does anyone have a solution?
How can I continue to use my same loading script, and keep the log from filling up?
Thank you.
View 9 Replies
View Related
May 9, 2007
How can i get ALL the selected items into the database? this loop only accepts one item. I have tried with a "clear" action, does not work.... protected void Button2_Click(object sender, EventArgs e) { if (Page.IsValid) { // Define data objects SqlConnection conn; SqlCommand comm; // Open the connection string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; // Initialize connection conn = new SqlConnection(connectionString); // Create command comm = new SqlCommand("INSERT INTO TestTabel (TestNavn) VALUES (@TestNavn)",conn); // Add command parameters foreach (ListItem item in TestListBox.Items) { if (item.Selected) { comm.Parameters.Add("@TestNavn", System.Data.SqlDbType.NVarChar); comm.Parameters["@TestNavn"].Value = Item.Text; } } // Enclose database code in Try-Catch-Finally try { // Open the connection conn.Open(); // Execute the command comm.ExecuteNonQuery(); // Reload page if the query executed successfully Response.Redirect("Default.aspx"); } catch(Exception Arg) { Response.Write(Arg.Message); // Display error message Label1.Text = "Error !"; } finally { // Close the connection conn.Close(); } } }
View 1 Replies
View Related
May 20, 2007
Hi,
I have SQL database 2000 which has one table Sheet1, I retrieved the columns in the ListBox, then chosed some of them and moved it to ListBox2.
The past scenario worked great, and I checked the moved values, it was succesfully moved, but when I tried to copy the values in ArrayList to do a select statement it didn't worked at all.
public string str;protected void Button3_Click(object sender, EventArgs e)
{ArrayList itemsSelected = new ArrayList(); string sep = ",";
//string str;for (int i = 0; i < ListBox2.Items.Count; i++)
{if (ListBox2.Items[i].Selected)
{
itemsSelected.Add(ListBox2.Items[i].Value);
}
int itemsSelCount = itemsSelected.Count; // integer variable which holds the count of the selected items.
str = ListBox2.Items[i].Value + sep;
Response.Write(str);
}
SqlConnection SqlCon = new SqlConnection("Data Source=AJ-166DCCD87;Initial Catalog=stat_rpt;Integrated Security=True;Pooling=False");
String SQL1 = "SELECT " + str + " from Sheet1"; SqlDataAdapter Adptr = new SqlDataAdapter(SQL1, SqlCon);
SqlCommandBuilder CB = new SqlCommandBuilder(Adptr);DataTable Dt = new DataTable();
Adptr.Fill(Dt);
//return Dt;
GridView1.DataBind();
SqlCon.Close();
}
I did some changes and the new error message is
Incorrect syntax near the keyword 'from'.
Thank you
View 6 Replies
View Related
Oct 23, 2007
Hi everyone, not sure if a this topic has been covered yet (a have been looking all day), but as I am still very new to this, my problem is as follows:
In the Try .. Catch block below, data is posted from a form and the SqlCommand.ExecuteScalar() statement returns a Unique Job ID.
I am attempting to populate a subordinate table for qualifications which are selected from a ListBox, but rather than using qualification titles, I am using the values.
My problem is that only one value (the first) gets posted multiple times, when multiple values are selected.
Looking at the For Each loop in the inner Try Catch block, I am wondering whether there is some sort of Index pointer that needs to be incremented, in order to establish new values further down the list.
I have seen no evidence that this is the case, save for the fact that the value stalls on just the first.
Any help would be appreciated.
===== CODE ===
Try
C4LConnection.Open()
JobPostingID = SqlJobPost.ExecuteScalar()Response.Write("<br />Selected Item: " & Qualifications.SelectedItem.Value)
Try
' Multiple Qualification EntriesSqlQualPost.Parameters.Add(New SqlParameter("@JobPostingID", SqlDbType.Int))
SqlQualPost.Parameters("@JobPostingID").Value = Int32.Parse(JobPostingID)SqlQualPost.Parameters.Add(New SqlParameter("@QualificationID", SqlDbType.Int))
SqlQualPost.Parameters("@QualificationID").Value = Int32.Parse(Qualifications.SelectedItem.Value)
If Qualifications.SelectedIndex > -1 ThenFor Each Item In Qualifications.Items
If Item.Selected ThenResponse.Write("<br />SelectedItem Value: " & Qualifications.SelectedItem.Text)
QualPostingID = SqlQualPost.ExecuteScalar()SqlQualPost.Parameters("@QualificationID").Value = Int32.Parse(Qualifications.SelectedItem.Value)
Response.Write("<br />Selected Item: " & Qualifications.SelectedItem.Value)
End If
Next
End IfCatch Exp As SqlException
failJobPost = True
lblError.Visible = TruelblError.Text = "Could not add qualifications <br />" & Exp.Message
End Try
failJobPost = FalseCatch Exp As SqlException
failJobPost = True
lblError.Visible = TruelblError.Text = "Error: could not post job to database <br />" & Exp.Message
Finally
C4LConnection.Close()
End Try
View 2 Replies
View Related
Jan 9, 2008
I have seen some information on this but have not understood fully the answers. I am fairly new to this and have spent the afternoon trying to work on this and although I have leant some really cool things I am no nearer. How do I get selected values from a LIstbox into a SQL statement using the IN command
First I loop through a List box control to get the multi selected values: Dim li As ListItemFor Each li In lbPClass.Items If li.Selected = True Then strPC += li.Value & ", " End IfNextLabel5.Text = strPC The result in the lable looks something like: 100, 101, 102 , I get rid of the trailing blank and commar with:Label6.Text = Left(Label5.Text, Trim(Len(Label5.Text) - 2)) I have created a parameter called @PROPCLASS that will use the values from the selected values in the listbox in a SQL query using an IN statement: Cmd.Parameters.Add(New OleDbParameter("@PROPCLASS", Label6.Text)) strSQL = "SELECT * FROM web_transfer WHERE ( PROP_CLASS IN (@PROPCLASS)) AND (ACRES >= @lowSize)AND (ACRES < @HighSize) AND (YEAR = @lowYear)AND (SALE_PRICE > @lowPrice) AND (SALE_PRICE < @highPrice) "
It is really the first bit of the WHERE clause I am interested in. The sql statement works if I either type in the actual values IN( 100, 101,102) or if I select only one value in the list box. If I select two then the sql statement does not work.
My question is: How do I get the values selected in the List box into my SQL statement Thank you in advance, s
View 1 Replies
View Related
Jun 29, 2004
I want that the user can chose several options from one ‘listbox’, and to do this, I have created two ‘listbox’, in the first one there are the options to select, and the second one is empty. Then, in order to select the options I want the user have select one or more options from the first ‘listbox’ and then click in a link to pass the options selected to the second ‘listbox’. Thus, the valid options selected will be the text and values in the second ‘listbox’. I have seen this system in some websites, and I think it is very clear.
Well, my question is, Is it possible to insert into the database all the values from a ‘listbox’ control? In my case from the second ‘listbox’ with all the values passed from the first one? If yes, in my database table I have to create one column (field) for every possible selected option?
Thank you,
Cesar
View 3 Replies
View Related
Feb 1, 2006
hello forum,
I need to grab a string value from a list box in from a web form, and pass it to a sql select command statement where that value is equal toall values in a database table(sql 2000).
example
zip code list box3315433254 845788547535454 selected value is 85475
I am putting that value in a string like this:
dim string_zip as stringstring_zip = zip_ListBox.text
Question, how do i pass that value to sql stament, i am using this but does not work.
SqlCommand1 = New SqlCommand("SELECT zip FROM table WHERE zip = string_zip", SqlConnection1)
View 5 Replies
View Related
May 23, 2008
I have a sql server database linked to my application. I have a table that I want one of the columns (Service Perfomed) to load in a list box. When I start the application nothing appears in the list box. What could I be doing wrong?
Here the code the visual studio created:
Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
Me.ServiceTableAdapter.Fill(Me.MaintenanceRecordsDataSet.Service)
End Sub
I've tried combo box, text box and these seem to work fine but not the list box.
View 1 Replies
View Related
Feb 27, 2007
I have a class that works fine using the SQLDataReader but when I try and duplicate the process using a Dataset instead of a SQLDataReader it returnsa a null value.
This is the code for the Method to return a datareader
publicSqlDataReader GetOrgID()
{
Singleton s1 = Singleton.Instance();
Guid uuid;
uuid = new Guid(s1.User_id);
SqlConnection con = new SqlConnection(conString);
string selectString = "Select OrgID From aspnet_OrgNames Where UserID = @UserID";
SqlCommand cmd = new SqlCommand(selectString, con);
cmd.Parameters.Add("@UserID", SqlDbType.UniqueIdentifier, 16).Value = uuid;
con.Open();
SqlDataReader dtr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
return dtr;
This is the code trying to accomplish the same thing with a Dataset instead.
public DataSet organID(DataSet dataset)
{
Singleton s1 = Singleton.Instance();
Guid uuid;
uuid = new Guid(s1.User_id);
string queryString = "Select OrgID From aspnet_OrgNames Where UserID = @UserID";
SqlConnection con = new SqlConnection(conString);
SqlCommand cmd = new SqlCommand(queryString, con);
cmd.Parameters.Add("@UserID", SqlDbType.UniqueIdentifier, 16).Value = uuid;
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = cmd;
adapter.Fill(dataset);
return dataset;
}
Assume that the conString is set to a valid connection string. The Singlton passes the userid in from some code in the code behind page ...this functionality works as well.
So assume that the Guid is a valid entry..I should return a valid dataset but its null.
Additionally if I change the sql query to just be Select * From aspnet_OrgNames I still get a null value...I am assuming I am doing something wrong trying to fill the dataset.
Any help would be appreciated.
View 2 Replies
View Related
Jan 14, 2000
MS SQL Enterprise Server, SP5, running under version 6.5.
I have recently been having a problem with the TempDb database
filling up. I originally started the database at 250 Mb but
recently expanded it to 500 Mb.
My last check of the activity on the server during an event
such as this produced the following information.
- Approx. 300 connections to primarily 2 databases.
- 4 active connections:
Connection 1 -SELECT on database 1 with 13,000 records
and a record size of approx. 300 bytes.
Connection 2 -SELECT on database 1 with 13,000 records
and a record size of approx. 300 bytes.
Connection 3 -SELECT on database 2 with 550 records
and a record size of approx. 100 bytes.
Connection 4 -Replication subscriber set at 100 transactions.
My questions are:
1. What processes may cause the TempDb database to fill up?
2. What processes prevent the database from purging?
Any information would be greatly appreciated.
Jim Story
View 2 Replies
View Related
Nov 2, 1999
We are having continual problems with our transaction log filling up on one of our major applications.
Does anyone know of a way or tool to read the transaction log? We want to determine what is causing this problem.
Thanks
View 2 Replies
View Related
May 4, 1999
Recently, we converted an Access database to SQL server 6.5. One of the processes that runs against the server is
missing a commit causing temporary stored procedures to fill up TEMPDB in the sysobjects table. The only way to
clear up TEMPDB is to stop and start SQL server when the database fills up. I wrote a quick and dirty stored
procedure to delete the affending rows out of the tempdb..sysobjects table, however, the database still registers as
full after the deletes.
Question:
does anyone know of a process/DBCC I can run against the tempdb..sysobjects table to regain the space in TEMPDB
without having to stop and restart SQL Server? I need a temporary solution while the programmer is debugging the
affending code.
Thanks!
TC
View 1 Replies
View Related
Dec 5, 1998
hello,
I've got replication set up as a publisher subscriber, to basically sync a primary server with a
backup server. My distribution log keeps filling up, I've got a perf alert for now to truncate it
at 75% full for now, but why does it fill up? it's size is about 1.5 gig
My tran log for my database will also not remove about 500mb of data as well, is there any way to
see what is going on?
Thanks
View 1 Replies
View Related