|
WScript.Sleep(2000)
Why did you post this in SQL forum?????
Die Energie der Welt ist konstant. Die Entropie der Welt strebt einem Maximum zu.
|
|
|
|
|
I have a TexBox and it's value stored in a database.
but whwe the entered value like ' , ' or ' ; '
there is some error occurred ,so how I can solve this problem.
|
|
|
|
|
that should not happen.
assuming your DB field is nvarchar, it should be able to hold whatever text you enter.
what is your database?
are you using SQLParameter?
maybe best show us your relevant code.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
OK,
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["AdNetConnectionString"].ToString();
Session["CampaignName"]= TexBox1.Text.ToString();
string sql;
sql = "insert into AdCampaign (CampaignName)values( ' " + Session["CampaignName"] + " ');
SqlCommand cmd = new SqlCommand(sql, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
|
|
|
|
|
I still don't know what your database is.
I see you are not using SQLParameter; it would almost certainly solve your problem. Read up on it, and use it; it will keep a lot of problems away, SQL injection vulnerability being one of them.
I would not move the data from the textbox through the session array into the SQL command; no need for such a detour. No need for ToString() either, the content of a TextBox is always a string.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
How to use a parameterized query, using your code as an example:
sql = "insert into AdCampaign (CampaignName) values(@myParameter)";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.Parameters.AddWithValue("myParameter", Session["CampaignName"]);
I.e. in your sql statement, no values are shown, but only the parameters; with SQL Server, parameter names use to start with an @. After having created the command object, you add all of your parameters with their respective values.
|
|
|
|
|
ok ,
my code is:
sql_Store_Sessions = "insert into AdCampaign (AccountID,AdType,SiteCategory,Language,Gender,Age,Keyword,MaxBudget,DailyBudget,CampaignName,AdHeadline,AdText,DisplayUrl,TargetUrl,BannerImg,ImgName,Date,Status)values(" + Session["SelectIdFromTableAccount"] + ",'" + Session["adType"] + "','" + Session["Category"] + "','" + Session["Language"] + "','" + Session["Gender"] + "','" + Session["Age"] + "',@AdvKeyword," + Session["MaxBudget"] + "," + Session["Daily_Budget"] + ",@CampaignName,@AdHeadLine,@AdText,@DisplayUrl,@DestinationUrl,@Banner_Img,@Img_Name,'" + DateTime.Now + "','Paused')";
SqlCommand cmd_Store_Sessions = new SqlCommand(sql_Store_Sessions, con);
cmd_Store_Sessions.Parameters.AddWithValue("CampaignName", Session["CampaignName"]);
cmd_Store_Sessions.Parameters.AddWithValue("AdHeadLine", Session["AdHeadLine"]);
cmd_Store_Sessions.Parameters.AddWithValue("AdText", Session["AdText"]);
cmd_Store_Sessions.Parameters.AddWithValue("DisplayUrl", Session["DisplayUrl"]);
cmd_Store_Sessions.Parameters.AddWithValue("DestinationUrl", Session["DestinationUrl"]);
cmd_Store_Sessions.Parameters.AddWithValue("Banner_Img", Session["Banner_Img"]);
cmd_Store_Sessions.Parameters.AddWithValue("Img_Name", Session["Img_Name"]);
con.Open();
cmd_Store_Sessions.ExecuteNonQuery();
con.Close();
but there is an error :
The parameterized query '(@AdvKeyword nvarchar(2),@CampaignName nvarchar(2),@AdHeadLine n' expects the parameter '@Banner_Img', which was not supplied
|
|
|
|
|
I think that happens when the value is null. C# null and database null are different. If you want to insert a null into the database you need to use DBNull.Value.
|
|
|
|
|
isn't that yet another reason for using SQLParameter?
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
|
I always prefer of using storedProcedure with I/O parama instant of hard coded sql statement.
Thanks
Md. Marufuzzaman
I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
|
|
|
|
|
SQL Server 2005
Database sizes 25-30Gb
There are only two sites running the software at the moment.
I've recently joined a very small new company, and taken on several existing software products. I'm very concerned about the sizes of their customers databases. I've checked that the log file has not grown excessivly which was not the case, after that i have looked through all the tables in the database and found that 95% of the storage is in two tables. Checking the storage allocation for both those tables i have found that each has around 25% of the sorage being used for data, and 75% for indexing. This seemed very wrong to me, can any one recomend a way of re indexing the tables so that the storage being used is lower. If its just a case of removing all the indexes and starting again is there any thing i should be aware of.
Thanks in advance for any replies. If more specific information is needed please let me know.
|
|
|
|
|
Sometimes the reality is indexing needs more space than the data itself, so 75% for indexing may not be out of line. You can simply backup the database and restore it (to a different location) so the database table and indexes are re-created. That way you can find out if the indexing really needs that much space or the original database needs compacting. Chances are if the indexing part of the original database needs compacting, the data part also needs compacting. The ratio may change but indexing still needs more space than the data itself.
|
|
|
|
|
this database has been freshly restored from a backup so i guess from what you have said that would rule out the compacting being required.
To give some more of an idea of the issue the tables that are being affected are used to store financial transactions, one table contains 7.7 million rows, the storage cost is 3.9gb for the data, and 16.4gb for the indexing. This amount of data is resulting in very slow processing of even simple select queries, and my thoughts are that to resolve the problem some kind of archiving needs to be implemented.
This is probably a dumb question but do the data types being indexed have a direct affect on the storage space required for the indexing. i.e. would indexing a column of the type guid be significantly more storage intensive than an int column.
Sorry if the question is overly simple, i've worked with sql databases in the past and never seen storage requirements even close to this.
|
|
|
|
|
The data types being indexed does not have impact on the size used to store the indexes. What you described indicates even more indexing is needed for the database table since some simple "select" queries are very slow. You may need to remove some indexes not being used by the program and add some new indexes based on the queries frequently conducted. When the needed index does not exist, "select" queries on such large tables will be very slow. I was once amazed by how much performance gains was brought by adding proper indexes when I was working on a large database table (similar to your case). So it may worth a try to get a close look at the database to find out what you need for it.
|
|
|
|
|
|
thank you, i'll have a thorough read through this asap.
|
|
|
|
|
If the data is forced into two main tables with little else going on I would expect them to be indexed to the hilt in order to get the data back out.
It all depends on the database construction and the associated business rules.
|
|
|
|
|
Hi,
I am looking for a generic database option which will be used to save some admininistration configuration information of a web application. I want to have the database generic and license free. For example, I do not want to use SQL Server or Oracle etc. But customer A can have sql server and Customer B can have Oracle, but this configuration information should be easy enough to be exported to other database systems. I was thinking about XML. But I heard sometimes the file gets too big to handle. Not sure if MS Access or admin site's inbuilt db system will help. If anybody knows any other light weight database system (it can be open source) which is easy enough to be exported to general database systems, please let me know the thoughts.
Thanks,
Vijay
|
|
|
|
|
This is one that you could take a look at: SQL Lite[^]
me, me, me
"The dinosaurs became extinct because they didn't have a space program. And if we become extinct because we don't have a space program, it'll serve us right!"
Larry Niven
|
|
|
|
|
XML is good for configuration. If you are concerned about it growing large, then I doubt it is configuration.
If you need a database, then try to be as database agnostic as you can be so different clients can use different databases -- make it configurable.
|
|
|
|
|
Good Afternoon,
I used a nice SQL insert/update program for years with MSSQL 2000, but was never able to get it past security to make it work with 2005. This weekend, out of frustration, I decided to take a shot at writing one of my own. In doing so, I attempted to list the databases that were on the server. I first tested the command in the Query analyzer and it worked fine, returning all the names of the databases. However, when I tried to use the exact same code in the application, every database name comes up as "master" in the array, so I cannot continue to propagate the tables without a named database. I cannot understand how the identical code can return different results in different places. Here is the code.
Appreciate your assistance....Thank you, Pat
string Sql = "SELECT name FROM sys.databases";
SqlCommand Comm = new SqlCommand(Sql, Conn);
SqlDataAdapter da = new SqlDataAdapter(Comm);
DataSet ds = new DataSet();
da.Fill(ds);
int cnt = ds.Tables[0].Rows.Count;
string[] dbs = new string[cnt];
for(int i = 0; i < cnt; i++)
{
dbs[i] = ds.Tables[0].Rows[0]["name"].ToString();
}
foreach(string s in dbs)
{
databases.Items.Add(s);
}
|
|
|
|
|
Cross-post, answers go here[^]
I are Troll
|
|
|
|
|
Hi,
I am working in conservation and I am sent and record various records of various insects to record. I use MS Access 2007 to import the records into. I have seperate tables for seperate years 2007, 2008, 2009 etc...(all tables have the exact same fields, just different records for each different table) What I need to do is take all this data and find out which species was the most recorded in a year or least recorded etc.. I want to do this with a report and a chart of some sort (Pie or bar I think might be best)
I have four fields on the table I wish to use the "Scientific Name" the "Location" the "Quantity" and the "Date"
1) How would I be able to take the Quantity field and find out the total numbers for each species using the Scientific name and creating a report for this? I could have 50 records with the same scientific name, but I would like totals for these. And same for all species recorded
2) Using what I said above, I'd like to create a report and chart on the top highest recorded numbers of 5 different species and another on the lowest recorded species in one table
3) Finally, using what I wanted to do above, I wanted to do this for years, to show how species are doing over years. All the records I have are in different tables with the same fields as I already mentioned, but how would I be able to use all the tables say "Species 2007" "Species 2008" etc.. to create totals for ech seperate species recorded using the "Scientific Name" field to get the species name.
Any help would be appreciated.
Dave
In the end we're all just the same
|
|
|
|
|
1) You should be able to use the query builder to do a group by query. IIRC there's a button with a plus sign that allows you to do that easily.
2) Create a query that sums the number (same as for 1?) and sorts by sum descending and select the top 5 records. Create a similar query but sort by ascending.
3) I think you will need a Union query where each part is a query same as those in 1 and 2 but the source for each part of the union will be the different tables.
Two points. First you might change the data model to have one table with a column to store the year instead of separate tables for each year (you could easily do that with an action query to insert records from the existing tables). That could simplify all your reporting.
Secondly, not used Access for years so there might be better ways.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
The only valid measurement of code quality: WTFs/minute.
|
|
|
|
|