Enable radiobuttonlist in grid on checkbox check - c#

My problem is:
I got data in the front end in this format :
Username : xxxx
First name : xxx
Last Name : XXX
Authorizations \this is a grid, with chheckbox and radiobtns
Domain Role
xyz User
bnv Admin
asd User_1
now I need to insert this data back to my table .
1 suggestion i got was : Use XML ... right track ? or is there some better way ( haven't worked with XML....yet :))

If I understood correctly, you want to insert bulk data to the database. Apart from XML you can also use SqlBulCopy class which is very efficient in inserting millions of records to the SQL database. You can find more details on this at MSDN
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlbulkcopy.aspx

Related

C#: How to check user console input against a column in a .csv?

Yo,
I am fairly new to C# and I'm making a small text based console RPG game just for practice and I was wondering if there was anyway I could make something similar to this:
Ask user for name
Ask user for password
Check if the name is in column 1 of a .csv file
If it is, check if the password is in column 2 and in the same row as the name
If everything checks out, load the values from columns 3 and 4 in the same row as
the name and password into corresponding values like health and level
Here's an example .csv if I didn't really explain it well:
"charactername", "password123", "health", "level"
"Oswald", "498562a", "100", "4"
"Hammerfist", "98457813", "77", "6"
So just for the sake of clarity, this is what I'm thinking:
Enter your username: Oswald
Enter your password: 498562a
Program reads through column 1 of the file looking for "Oswald" and finds a match
Program then checks to see if the password value is in the same row but in
column 2 of the file and checks to see if it matches the user input, it matches it
Program then loads the health and level values into character variables
Entrance Successful
Is there a way to do this? Am I overlooking a simple solution? Or should I try and go about it a different way? I'm just don't want to hard code the values into a Dictionary or List or Array or whatever. I'm not looking for security at this stage either, it's just for practice and fun.
Thanks in advance! Let me know if you need a better understanding of what I'm trying to do and I'll try to explain the best I can.
There are two ways to go about reading csv
Just like standard text file, line by line. Then parse your line into array of columns and get your values
Using Microsoft.ACE.OLEDB.version
OleDbconnection connection = new OleDbConnection();
connection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Documents\file.csv;Extended Properties=\"Text;HDR=Yes;FORMAT=Delimited\"";
This way you can load DataTable on the start of your app and query this table just like Sql database.
notice : HDR=Yes means that first row is a header row

Sitecore WFFM check duplicate email

I am developing a form validation action for WFFM, which will not allow people to use same email for submitting multiple entries. So far, the only document I've got is the WFFM v2.3 Ref from Sitecore SDN, which only have few example of how to access submitted data form by form.
I don't know how to select data by using field value. So, my current solution is to retrieve all data from database and check all email fields; which doesn't seem right when putting in scale.
Do you have any code snippet that can help me add GridFilter like email="abc#def.com", if count > 0 definitely the email is duplicated?
Thank you.
Instead of finding the API supporting this very own demand, I found it easier to make a direct connection to the WFFM database and look up for what I want. Thank you for reading this.
The webforms database has 3 tables only. If for example, you want the list of email ids available in the 'Support Form' below:
Here's the query:
SELECT DISTINCT Value FROM [dbo].[Field]
WHERE FieldId = '5F5643B6-0535-49D8-B3C9-CF8E65A415C0'
Field Id corresponds to the field GUID of the form:
Ps. WebForms connections string should be available in App_Config\Include\forms.config.

Time out while i fetch data from SQL in Asp.net MVC

I hava a database which only have 2 table Object , User ,
Obviously user table has information about all user and the object table have millions of records
ObjectTable
Id (int)
Text1 (nvarchar(max))
Text2 (nvarchar(max))
I am trying to make a translator , first of all i put all data in database like following
1 : Good , Well
2 : Bad , NotWell
3 : Man , Husband Of Women
if suppose i havae 2 text boxes in my site user enter following text
Good Bad Man
then i will split that string on space and then i will have an array of string now i will took first element of array and go to server to find that wheather there is any match of Good in my database if i found match then i will replace that value with that Text2 like we have Well for Good which took too much time to translate and sometime it gives Request Timed Out . So , what is the best way to deal with it
You do not provide a lot of information to help you about your timeout problem.
Only things I can tell you are :
first of all, check that there are indexes on your Text1 and Text2 columns. If not, add it
look at your sql query. It should be SELECT * FROM OBJECT WHERE TEXT1='Good' (maybe add a top 100 to avoid returning to many things with LIKE ).
For the index to run smoothly, there should be no function called on column TEXT1 (like uppercase or trim). If you use a like, it should be TEXT1 LIKE 'good%' (% at the end)
if you use a like, beware of not returning your whole table on a empty entry, % or _ entry ( LIKE '%', LIKE '%%', LIKE '_%' can be bad things)
why use nvarchar(max) if you are just storing words ?
don't forget to sanitize your entries to avoid sql injection

How to arrange this data in columns?

I have a mysql database. In which there are 50 columns of detail.
Detail 1, Detail2, Detail3...... Detail50.
I have the website locally so i am scrapping from myself. The site is not in order no tags and names data is just in form of text line by line, so this was the only option to take what i get line by line and save to DB. So every line gets a column from 1-50....
Some pages have 10 columns other have 50 and the data is in no order now i have the DB,how can i sort them any suggestion ,idea is welcome.
This image will make it more clear:
So You can see Sometimes its Inner Diameter in Detail4 and sometime in 1, these are just examples i would have hard coded but there are too many possibilities, but the repeating words all have the same staring name just values different .Any chance to atleast make 50 % of the data in order the ones with same 4-5 starting words like
part,inner,diameter,oil filter etc.
Any suggestion or ideas can it be done in mysql or C# code.....
Thank you
your approach is totally wrong, but if you want to go this way, just make a table with two columns 'id' and 'details' ... make an insert for each column for the specific product ID.
After that you can use a SELECT like that:
select SUBSTRING(details, 14) from products where details like 'Inner Diameter%' and id = 'my_product_id';

knowing if a string will be truncated when updating database

I'm working on a software that takes a csv file and put the data in a sqlserver. i'm testing it with bad data now and when i make a data string to long (in a line) to be imported in the database i got the error : String or binary data would be truncated the statement has been terminate. that's normal and that's what i should expect. Now i wanna detecte those error before the update to the database. Is there any clever way to detecte this?
The way my software work is that i importe every line in a dataset then show the user the data that will be imported. Then he can click a button to do the actual update. i then do a dataAdapter.Update( Dataset, "something" ) to make the update to the database.
The probleme is that the error row terminate all the update and report the error. So i want to detect the error before i do the update to the server so the other rows will be inserted.
thanks
You will have to check the columns of each row. See if one exceeds the maximum specified in the database, and if yes, exclude it from being inserted.
A different solution would be to explicitly truncate the data and insert the truncated content, which could be done by using SubString.
The only way that I know of is to pre-check the information schema for the character limit:
Select
Column_Name,
Character_Maximum_Length
From
Information_Schema.Columns
Where
Table_Name = 'YourTableName'
What you need is the column metadata.
MSDN: SqlConnection.GetSchema Method
Or, if you have opened a recordset on your database, another solution would be to browse the field object to use its length to truncate the string. For example, with ADO recordset/VB code, you could have some code like this one:
myRecordset.fields(myField) = left(myString, myRecordset.fields(myField).DefinedSize)

Categories