 |

|
As Naerling and thatraja pointed out, there is no question, and we don't spood-feed, read the article thatraja linked, or if you are lazy brain-wise, buy Linqer (or any other SQL to LINQ conversion tool).
|
|
|
|

|
This is my stored procedure and c# code .. the column Patient_ID_NO is not inserting any value , and i want to display idcount value in message box ,.
ALTER PROCEDURE [dbo].[Transaction]
(
@Patient nvarchar(50),
@E_TO nvarchar(50),
@R_type int,
@User_id uniqueidentifier,
@ReportType nvarchar(50),
@Patient_no int,
@Patient_ID_NO int,
@idcount numeric(18,0) output
)
AS
BEGIN
declare @tempid numeric(18,0)
set @tempid = 0;
declare @idcnt numeric(18,0)
select @idcnt =isnull( max(idcount),0) from Transactions where year(R_date)=year(getdate())
if (@idcnt =0)
set @tempid=1
else
set @tempid = @idcnt +1
INSERT INTO dbo.Transactions (Patient,E_TO,R_date,R_from,User_id,report_type,Patient_no,Patient_ID_NO,idcount)values (@Patient,@E_TO,getdate(),@R_type,@User_id,@ReportType,@Patient_no,@Patient_ID_NO,@tempid)
END
C# code
public static void Message(String message, Control cntrl)
{
ScriptManager.RegisterStartupScript(cntrl, cntrl.GetType(), "alert"
, "alert('" + message + "');", true);
}
protected void Button1_Click(object sender, EventArgs e)
{
if (PatID_NO.Text != "")
{
SIDC a = new SIDC();
int n;
n = a.valid_re_int(PatID_NO.Text);
if (n > 3)
{
Message("Error as well as make sure identification number"", this);
return;
}
else
PatID_NO.Focus();
}
else
PatID_NO.Focus();
try
{
if (NameTxtBx.Text == "" || ToTxtBx0.Text == "" || DropDownList1.SelectedIndex == 0 || RadioButtonList2.SelectedIndex == -1 || ( PatID_NO.Text == "")|| (Convert.ToUInt64(PatNo.Text) <= 0) || (Convert.ToUInt64(PatNo.Text) > 200000000))
{
Message("Error: Please make sure that all fields are entered correctly", this);
return;
}
else
{
try
{
string Patient_name = NameTxtBx.Text, Export_TO = ToTxtBx0.Text, repType = RadioButtonList2.SelectedValue ;
int PatNoVal;
PatNoVal = Convert.ToInt32(PatNo.Text);
PatNoVal = int.Parse(PatNo.Text);
Decimal PatID;
PatID = Convert.ToInt32(PatID_NO.Text);
PatID = int.Parse(PatID_NO.Text);
DateTime today = Convert.ToDateTime(DateTime.Now.ToShortDateString());
System.Nullable idcount = null;
int? replay_To_type = Int16.Parse(DropDownList1.SelectedValue);
try
{
TransDataContext db = new TransDataContext();
try
{
var q = db.Transaction(Patient_name, Export_TO,replay_To_type,null,repType,PatNoVal,PatID,ref idcount);
foreach (Transaction Transaction in Transactions)
{
Response.Write("your id is" + Transaction.idcount + " ");
}
}
catch
{
Message("block 3:There is an error in the entry form required, please contact the Department of Computer", this);
}
}
catch
{
Message("block 2: ERROR CONTACT YOUR SYSTEM ADMINISTRATOR", this);
}
PatNo.Text = "";
NameTxtBx.Text = "";
ToTxtBx0.Text = "";
DropDownList1.SelectedIndex = -1;
RadioButtonList2.SelectedIndex = -1;
}
catch
{
Message(" ERROR 20", this);
}
}
}
catch
{
Message("Error: Make sure you enter the data correctly ", this);
}
}
protected void DropDownList1_DataBound(object sender, EventArgs e)
{
DropDownList1.Items.Insert(0, "--Select One--");
}
public IEnumerable Transactions { get; set; }
public decimal? PatID { get; set; }
}
}
|
|
|
|

|
Decimal PatID;
PatID = Convert.ToInt32(PatID_NO.Text);
PatID = int.Parse(PatID_NO.Text); Should that not be:int PatID;
if (!int.TryParse(PatID_NO.Text, out PatID))
{
}The reason there's nothing in idcount is because you haven't set it to anything in your stored procedure. Try SET @idcount = SCOPE_IDENTITY() Finally, could you please use the <pre> tag to format your snippets? I had a real problem reading your post. When you enter a snippet, highlight it in the editor and hover over the code tag just above the message editor - a drop down list appears allowing you to choose the appropriate language.
modified 20 Jun '12 - 12:29.
|
|
|
|

|
i will try ur code in my office . hope it will work...
i have auto increment value in idcount it will increment till one year when the next year start it will change to 1 again...
i tried SET @idcount = SCOPE_IDENTITY().. but the value which is in idcount column is different than scope identity,which i try to display in message box ...
how can i use return ? in this stored procedure so that the value which i am inserting should be displayed..?
|
|
|
|

|
Using VS C# 2010 Express, with project Target Framework=3.5
I'm new to Linq to Entities. I'm trying to add it to a small video project. I am reading and writing to a database video clip information.
When the following line executes:
playsEntities playsContext = new playsEntities();
I get an exception:
Could not load file or assembly 'System.Drawing, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
This seems to be related to the connection string which causes all the referenced assemblies to be searched for the database model. If I add the code to a new Windows Forms appliction, there is no error. I think it is a result of Microsoft.DirectX.AudioVideoPlayback assembly in my project which I am using for video playback.
I can't figure out how to prevent this error.
I have tried all kinds of combinations in the connection string but nothing works. I have tried setting "Metadata Artifacts" to "Embed in Output Assembly" and "Copy to output directory".
This is the last Connnection string I have tried in the from app.config:
<add name="playsEntities"
connectionString="metadata=
res://Simple playanalyzer.exe/Model1.csdl|
res://Simple playanalyzer.exe/Model1.ssdl|
res://Simple playanalyzer.exe/Model1.msl;
provider=System.Data.SqlClient;provider connection string="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\plays.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" /></connectionStrings>
Of course, the original, default connection string was:
<add name="playsEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\plays.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" /></connectionStrings>
From what I have read, I just need to be able to set the connection string so that the entity model files can be found at runtime.
Suggestions please?
Thanks,
Glen
|
|
|
|

|
Your problem is likely because the assembly seems to require the .NET framework 1.0, which is mot typically installed nowdays. See if there is a newer version, of if you have access to the source, update it yourself. If no source is available, try using ildasm to create an il file, and modify the references to point from 1 : 0 : 0 : 0 to 4 : 0 : 0 : 0 (remove the spaces, I added them to prevent a smiley from being inserted.) The references section should be at the top of the file. You can then use ilasm to recreate the assembly.
Bill Gates is a very rich man today... and do you want to know why? The answer is one word: versions.
Dave Barry
Read more at BrainyQuote[ ^]
|
|
|
|

|
how can write linq insert ,update,delete queries
|
|
|
|

|
Where have you looked, there are lots of examples....
here is one[^]
I don't speak Idiot - please talk slowly and clearly
'This space for rent'
Driven to the arms of Heineken by the wife
|
|
|
|

|
what is linq. whay it is used for.
|
|
|
|

|
Typing your question, or rather simply the word LINQ, into Google, reveals lots of information[^].
Programming is work, it isn't finger painting. Luc Pattyn
|
|
|
|
|

|
linq is a language feature of c#(.net language) that enables you to fire query over any collection such as array.
Ex int[] numArray = { 1, 2, 3, 4, 5, 6, 7 };
var query = from num in numArray
where num > 5
select num;
var filteredArray = query.ToArray();
foreach (var item in filteredArray)
{
MessageBox.Show(item.ToString());
}
//MessageBox will appear twice with value 6 and 7
//the query is a linq query
|
|
|
|

|
He was a character in a popular video game franchise that started in the 1980s.
CPallini wrote: You cannot argue with agile people so just take the extreme approach and shoot him.
:Smile:
|
|
|
|

|
I must have missed the no jokes in the programming forums rule.
CPallini wrote: You cannot argue with agile people so just take the extreme approach and shoot him.
:Smile:
|
|
|
|

|
Did you miss the joke icon when you posted the joke? Nevermind, I've just 5ed to compensate.
|
|
|
|

|
As a matter of fact I did. Forgot that it defaults to "Answer". Whoops.
CPallini wrote: You cannot argue with agile people so just take the extreme approach and shoot him.
:Smile:
|
|
|
|

|
missclicked my vote 1... :(
|
|
|
|
|

|
I've seen some good information on this site as to how to set up a Windows Forms application using the Entity Framework and Data Binding the controls on the forms to the Entity Framework. And also have a SQL Server at the bottom of the stack. But, there is one thing that I don't understand. I could be missing something. But it seems that, in the examples that I've seen, that the Form controls, the entity framework, and the binding between are all running off of the same thread. If that's true, then I would think that I could expect the UI to appear to hang while waiting on a round trip query to the Database. It would seem that it would be better to make any Database query run in a separate thread for performance reasons. Or, perhaps it's the case that optimizations along these lines take place, by default, under the hood in ObjectContext and I just don't know it. Could someone please enlighten me?
|
|
|
|

|
Hi all
How can I use with linq command like this:
INSERT INTO tablename1 (column1, column2, column3,...)
SELECT (column4, column5, column6,...) FROM tablename2
I hop to be clear
Thanes
modified 10 Apr '12 - 11:00.
|
|
|
|

|
I think you could do something like this:
var SeletcToInsert = from tbl2 in tablename2
where ...
select new A
{
...
};
tablename1.InsertAllOnSubmit(toInsert);
dc.SubmitChanges();
|
|
|
|
|

|
I have 1 WinForm with 2 Combo boxes, first one is filled with Employee names, and the second one is supposed to be filled with tasks that are affected to every employee listed in the first combo. But could not get the following code to run for the second combo:
private void Form1_Load(object sender, EventArgs e)
{
using (LINQtoEntitiesEntities MyEntities = new LINQtoEntitiesEntities())
{
ObjectQuery Emp = MyEntities.Employee;
comboBox1.DataSource = (from u in Emp select new { u.ID, u.LastName }).ToList();
comboBox1.ValueMember = "ID";
comboBox1.DisplayMember = "LastName";
}
}
private void comboBox1_TextChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex.ToString() == "0") return;
using (LINQtoEntitiesEntities MyEntities = new LINQtoEntitiesEntities())
{
label1.Text = comboBox1.SelectedValue.ToString();
ObjectQuery Tsk = MyEntities.Tasks;
comboBox2.DataSource = (from t in Tsk where t.EmloyeeID.ToString() == comboBox1.SelectedValue.ToString() select new { t.ID, t.TaskName }).ToList();
comboBox2.ValueMember = "ID";
comboBox2.DisplayMember = "TaskName";
}
}
Could fill normally ComboBox1, but not ComboBox2, and it would be great if first line of ComboBox1 is blank.
|
|
|
|

|
Does the event fire for comboBox1_TextChanged, if not rather try the SelectedIndexChanged event.
If EmployeeID is an int, rather convert to toInt32 than toString, reason is that "1" != "1 ", so it is better practice to compare int values.
Sami L wrote: (from t in Tsk where t.EmloyeeID.ToString() == comboBox1.SelectedValue.ToString()
int selectedID;
if(int.TryParse(comboBox1.SelectedValue.ToString(), out selectedID))
{
comboBox2.DataSource = (from t in Tsk
where t.EmloyeeID == selectedID
select new { t.ID, t.TaskName }).ToList();
}
To insert an empty value first in comboBox1 use the insert command after setting the datasource in the form load. the index will be 0 to insert as the first item.
comboBox1.Items.Insert(index, object);
No matter how long he who laughs last laughs, he who laughs first has a head start!
|
|
|
|
|
 |
|