ช่วยดู error และ code นี้ให้ด้วยครับ Warning: odbc_exec(0 [function.odbc-exec]: SQL error: [Microsoft
Warning: odbc_exec(0 [function.odbc-exec]: SQL error: [Microsoft][ODBC] Microsoft Access Driver] The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index, or redefine the index to permit duplicate entries and try again., SQL state 23000 in SQLExecDirect in
C:\Inetpub\scripts\Car_reservation\Admin\AddAccep_Driver.php on line 7
code:
1 <?
2 $dsn_name="CarProgram";
3 $username="";
4 $password="";
5 $connect=odbc_connect($dsn_name, $username, $password) or die ("ติดต่อ DSN ไม่ได้");
6 $sql="insert into driver (firstname, lastname, age) values ('N', 'B', '30')";
7 $execute=odbc_exec($connect, $sql) or die ("เอ็กซิคิวส์คำสั่งไม่ได้");
8 $id=odbc_result($execute, "id");
9 $firstname=odbc_result($execute, "firstname");
10 $lastname=odbc_result($execute, "lastname");
11 $age=odbc_result($execute, "age");
12 odbc_close($connect);
13 echo"โปรแกรมได้บันทึกข้อมูลเรียบร้อยแล้ว";
14 ?>
จุดประสงค์คือ ต้องการเพิ่มข้อมูลเข้าไปในตาราง ถ้าเพิ่มโดยกำหนดค่าลงไปในบรรทัดที่ 6 สามารถเพิ่มข้อมูลเข้าไปในตารางฐานข้อมูลได้ แต่เพิ่มผ่านฟอร์มไม่ได้ เมื่อกด submit โดยผ่านฟอร์ม จะพบ error เหมือนข้างบนTag : - - - -
Date :
12 เม.ย. 2550 15:47:06
By :
suphannee
View :
2905
Reply :
8
ยังไงหรือครับ Code ที่ Error นะครับ แล้ว form ด้วยอะคับ ขอดูหน่อยนะครับ
Date :
12 เม.ย. 2550 22:02:52
By :
JCChan
มีปัญหาตรง primary ของ table driver คุณใช้ฟิลไรเปงไพรมารี่อ่า ขอดู structure data หน่อย
Date :
12 เม.ย. 2550 22:17:07
By :
bomครหวัน
การทำ primary key อะคับ คุณจะนำไปคำนวณ ป่าวละครับ ถ้าไม่เอาไปคำนวณส่วนใหญ่นะ เขาใช้เป็น varchar ใน Mysql แต่ถ้าเป็น Access คุณจะทำเป็น (Driver_No int(10) not null auto_increment); หรือจะไม่ Auto Increment ก็ได้นะครับ
โดย ทำ count++ เอง อะคับ แต่ ค่า Primary มันจะซ้ำไม่ได้ และ Null ไม่ได้นะครับ
Date :
12 เม.ย. 2550 22:35:41
By :
JCChan
ของผมก็เป็นเหมือนกันครับ VB + Access 2003
Date :
2010-11-12 21:05:18
By :
อดิศร มีใจใส
Code
The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again.
มันขึ้นแบบนี้อะครับแก้ยังไงครับนี้ นี้คือ คำสั่งครับ
Code (VB.NET)
If txtName.Text = "" Or txtModelName.Text = "" Or txtModel.Text = "" Or txtDetail.Text = "" Or txtID.Text = "" Then
MessageBox.Show("All fields Are Required", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
myqry = "INSERT INTO tblProduct(ProID,ProName,ModelName,Model,Prodetail) "
myqry = myqry + "VALUES('" & txtID.Text & "','" & txtName.Text & "','" & txtModelName.Text & "','" & txtModel.Text & "','" & txtDetail.Text & "')"
mycmd = New OleDbCommand
With mycmd
.CommandText = myqry
.Connection = conn
.ExecuteNonQuery()
End With
Call Set1()
End If
ส่วนดาต้าเบสครับ
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:msprop="urn:schemas-microsoft-com:xml-msprop">
<xs:annotation>
<xs:appinfo source="urn:schemas-microsoft-com:xml-msdatasource">
<DataSource DefaultConnectionIndex="0" FunctionsComponentName="QueriesTableAdapter" Modifier="AutoLayout, AnsiClass, Class, Public" SchemaSerializationMode="IncludeSchema" xmlns="urn:schemas-microsoft-com:xml-msdatasource">
<ConnectionRefs>
<DesignConnectionRef Name="databaseConnectionString1 (MySettings)" />
</ConnectionRefs>
<Connections>
<Connection AppSettingsObjectName="MySettings" AppSettingsPropertyName="databaseConnectionString1" ConnectionStringObject="" IsAppSettingsProperty="true" Modifier="Assembly" Name="databaseConnectionString1 (MySettings)" PropertyReference="ApplicationSettings.WindowsApplication2.My.MySettings.GlobalReference.Default.databaseConnectionString1" Provider="System.Data.OleDb" />
</Connections>
<TableRefs>
<DesignTableRef Name="tblProduct">
<ColumnRefs>
<DesignColumnRef Name="ProID" />
<DesignColumnRef Name="ProName" />
<DesignColumnRef Name="ModelName" />
<DesignColumnRef Name="Model" />
<DesignColumnRef Name="ProDetail" />
</ColumnRefs>
<SourceRefs />
</DesignTableRef>
</TableRefs>
<Tables>
<TableAdapter BaseClass="System.ComponentModel.Component" DataAccessorModifier="AutoLayout, AnsiClass, Class, Public" DataAccessorName="tblProductTableAdapter" GeneratorDataComponentClassName="tblProductTableAdapter" Name="tblProduct" UserDataComponentName="tblProductTableAdapter">
<MainSource>
<DbSource ConnectionRef="databaseConnectionString1 (MySettings)" DbObjectName="tblProduct" DbObjectType="Table" FillMethodModifier="Public" FillMethodName="Fill" GenerateMethods="Both" GenerateShortCommands="true" GeneratorGetMethodName="GetData" GeneratorSourceName="Fill" GetMethodModifier="Public" GetMethodName="GetData" QueryType="Rowset" ScalarCallRetval="System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" UseOptimisticConcurrency="true" UserGetMethodName="GetData" UserSourceName="Fill">
<DeleteCommand>
<DbCommand CommandType="Text" ModifiedByUser="false">
<CommandText>DELETE FROM `tblProduct` WHERE ((`ProID` = ?) AND ((? = 1 AND `ProName` IS NULL) OR (`ProName` = ?)) AND ((? = 1 AND `ModelName` IS NULL) OR (`ModelName` = ?)) AND ((? = 1 AND `Model` IS NULL) OR (`Model` = ?)) AND ((? = 1 AND `ProDetail` IS NULL) OR (`ProDetail` = ?)))</CommandText>
<Parameters>
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="Original_ProID" Precision="0" ProviderType="VarWChar" Scale="0" Size="0" SourceColumn="ProID" SourceColumnNullMapping="false" SourceVersion="Original" />
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="IsNull_ProName" Precision="0" ProviderType="Integer" Scale="0" Size="0" SourceColumn="ProName" SourceColumnNullMapping="true" SourceVersion="Original" />
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="Original_ProName" Precision="0" ProviderType="VarWChar" Scale="0" Size="0" SourceColumn="ProName" SourceColumnNullMapping="false" SourceVersion="Original" />
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="IsNull_ModelName" Precision="0" ProviderType="Integer" Scale="0" Size="0" SourceColumn="ModelName" SourceColumnNullMapping="true" SourceVersion="Original" />
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="Original_ModelName" Precision="0" ProviderType="VarWChar" Scale="0" Size="0" SourceColumn="ModelName" SourceColumnNullMapping="false" SourceVersion="Original" />
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="IsNull_Model" Precision="0" ProviderType="Integer" Scale="0" Size="0" SourceColumn="Model" SourceColumnNullMapping="true" SourceVersion="Original" />
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="Original_Model" Precision="0" ProviderType="VarWChar" Scale="0" Size="0" SourceColumn="Model" SourceColumnNullMapping="false" SourceVersion="Original" />
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="IsNull_ProDetail" Precision="0" ProviderType="Integer" Scale="0" Size="0" SourceColumn="ProDetail" SourceColumnNullMapping="true" SourceVersion="Original" />
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="Original_ProDetail" Precision="0" ProviderType="VarWChar" Scale="0" Size="0" SourceColumn="ProDetail" SourceColumnNullMapping="false" SourceVersion="Original" />
</Parameters>
</DbCommand>
</DeleteCommand>
<InsertCommand>
<DbCommand CommandType="Text" ModifiedByUser="false">
<CommandText>INSERT INTO `tblProduct` (`ProID`, `ProName`, `ModelName`, `Model`, `ProDetail`) VALUES (?, ?, ?, ?, ?)</CommandText>
<Parameters>
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="ProID" Precision="0" ProviderType="VarWChar" Scale="0" Size="0" SourceColumn="ProID" SourceColumnNullMapping="false" SourceVersion="Current" />
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="ProName" Precision="0" ProviderType="VarWChar" Scale="0" Size="0" SourceColumn="ProName" SourceColumnNullMapping="false" SourceVersion="Current" />
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="ModelName" Precision="0" ProviderType="VarWChar" Scale="0" Size="0" SourceColumn="ModelName" SourceColumnNullMapping="false" SourceVersion="Current" />
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="Model" Precision="0" ProviderType="VarWChar" Scale="0" Size="0" SourceColumn="Model" SourceColumnNullMapping="false" SourceVersion="Current" />
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="ProDetail" Precision="0" ProviderType="VarWChar" Scale="0" Size="0" SourceColumn="ProDetail" SourceColumnNullMapping="false" SourceVersion="Current" />
</Parameters>
</DbCommand>
</InsertCommand>
<SelectCommand>
<DbCommand CommandType="Text" ModifiedByUser="false">
<CommandText>SELECT ProID, ProName, ModelName, Model, ProDetail FROM tblProduct</CommandText>
<Parameters />
</DbCommand>
</SelectCommand>
<UpdateCommand>
<DbCommand CommandType="Text" ModifiedByUser="false">
<CommandText>UPDATE `tblProduct` SET `ProID` = ?, `ProName` = ?, `ModelName` = ?, `Model` = ?, `ProDetail` = ? WHERE ((`ProID` = ?) AND ((? = 1 AND `ProName` IS NULL) OR (`ProName` = ?)) AND ((? = 1 AND `ModelName` IS NULL) OR (`ModelName` = ?)) AND ((? = 1 AND `Model` IS NULL) OR (`Model` = ?)) AND ((? = 1 AND `ProDetail` IS NULL) OR (`ProDetail` = ?)))</CommandText>
<Parameters>
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="ProID" Precision="0" ProviderType="VarWChar" Scale="0" Size="0" SourceColumn="ProID" SourceColumnNullMapping="false" SourceVersion="Current" />
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="ProName" Precision="0" ProviderType="VarWChar" Scale="0" Size="0" SourceColumn="ProName" SourceColumnNullMapping="false" SourceVersion="Current" />
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="ModelName" Precision="0" ProviderType="VarWChar" Scale="0" Size="0" SourceColumn="ModelName" SourceColumnNullMapping="false" SourceVersion="Current" />
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="Model" Precision="0" ProviderType="VarWChar" Scale="0" Size="0" SourceColumn="Model" SourceColumnNullMapping="false" SourceVersion="Current" />
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="ProDetail" Precision="0" ProviderType="VarWChar" Scale="0" Size="0" SourceColumn="ProDetail" SourceColumnNullMapping="false" SourceVersion="Current" />
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="Original_ProID" Precision="0" ProviderType="VarWChar" Scale="0" Size="0" SourceColumn="ProID" SourceColumnNullMapping="false" SourceVersion="Original" />
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="IsNull_ProName" Precision="0" ProviderType="Integer" Scale="0" Size="0" SourceColumn="ProName" SourceColumnNullMapping="true" SourceVersion="Original" />
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="Original_ProName" Precision="0" ProviderType="VarWChar" Scale="0" Size="0" SourceColumn="ProName" SourceColumnNullMapping="false" SourceVersion="Original" />
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="IsNull_ModelName" Precision="0" ProviderType="Integer" Scale="0" Size="0" SourceColumn="ModelName" SourceColumnNullMapping="true" SourceVersion="Original" />
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="Original_ModelName" Precision="0" ProviderType="VarWChar" Scale="0" Size="0" SourceColumn="ModelName" SourceColumnNullMapping="false" SourceVersion="Original" />
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="IsNull_Model" Precision="0" ProviderType="Integer" Scale="0" Size="0" SourceColumn="Model" SourceColumnNullMapping="true" SourceVersion="Original" />
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="Original_Model" Precision="0" ProviderType="VarWChar" Scale="0" Size="0" SourceColumn="Model" SourceColumnNullMapping="false" SourceVersion="Original" />
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="Int32" Direction="Input" ParameterName="IsNull_ProDetail" Precision="0" ProviderType="Integer" Scale="0" Size="0" SourceColumn="ProDetail" SourceColumnNullMapping="true" SourceVersion="Original" />
<Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="String" Direction="Input" ParameterName="Original_ProDetail" Precision="0" ProviderType="VarWChar" Scale="0" Size="0" SourceColumn="ProDetail" SourceColumnNullMapping="false" SourceVersion="Original" />
</Parameters>
</DbCommand>
</UpdateCommand>
</DbSource>
</MainSource>
<Mappings>
<Mapping SourceColumn="ProID" DataSetColumn="ProID" />
<Mapping SourceColumn="ProName" DataSetColumn="ProName" />
<Mapping SourceColumn="ModelName" DataSetColumn="ModelName" />
<Mapping SourceColumn="Model" DataSetColumn="Model" />
<Mapping SourceColumn="ProDetail" DataSetColumn="ProDetail" />
</Mappings>
<Sources />
</TableAdapter>
</Tables>
<RelationRefs />
<SourceRefs />
<Sources />
</DataSource>
</xs:appinfo>
</xs:annotation>
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true" msprop:Generator_UserDSName="NewDataSet" msprop:Generator_DataSetName="NewDataSet">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="tblProduct" msprop:Generator_TableClassName="tblProductDataTable" msprop:Generator_TableVarName="tabletblProduct" msprop:Generator_TablePropName="tblProduct" msprop:Generator_RowDeletingName="tblProductRowDeleting" msprop:Generator_UserTableName="tblProduct" msprop:Generator_RowChangingName="tblProductRowChanging" msprop:Generator_RowEvHandlerName="tblProductRowChangeEventHandler" msprop:Generator_RowDeletedName="tblProductRowDeleted" msprop:Generator_RowEvArgName="tblProductRowChangeEvent" msprop:Generator_RowChangedName="tblProductRowChanged" msprop:Generator_RowClassName="tblProductRow">
<xs:complexType>
<xs:sequence>
<xs:element name="ProID" msprop:Generator_ColumnVarNameInTable="columnProID" msprop:Generator_ColumnPropNameInRow="ProID" msprop:Generator_ColumnPropNameInTable="ProIDColumn" msprop:Generator_UserColumnName="ProID">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="255" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="ProName" msprop:Generator_ColumnVarNameInTable="columnProName" msprop:Generator_ColumnPropNameInRow="ProName" msprop:Generator_ColumnPropNameInTable="ProNameColumn" msprop:Generator_UserColumnName="ProName" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="255" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="ModelName" msprop:Generator_ColumnVarNameInTable="columnModelName" msprop:Generator_ColumnPropNameInRow="ModelName" msprop:Generator_ColumnPropNameInTable="ModelNameColumn" msprop:Generator_UserColumnName="ModelName" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="255" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Model" msprop:Generator_ColumnVarNameInTable="columnModel" msprop:Generator_ColumnPropNameInRow="Model" msprop:Generator_ColumnPropNameInTable="ModelColumn" msprop:Generator_UserColumnName="Model" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="255" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="ProDetail" msprop:Generator_ColumnVarNameInTable="columnProDetail" msprop:Generator_ColumnPropNameInRow="ProDetail" msprop:Generator_ColumnPropNameInTable="ProDetailColumn" msprop:Generator_UserColumnName="ProDetail" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="255" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:unique name="Constraint1" msdata:PrimaryKey="true">
<xs:selector xpath=".//tblProduct" />
<xs:field xpath="ProID" />
</xs:unique>
</xs:element>
</xs:schema>
Date :
2012-06-13 16:20:36
By :
Mr'ก
ขอแก้ดาต้าเบสแปปนึงครับนี่ครับ
ProID
ProName
ModelName
Model
Prodetail
Date :
2012-06-13 16:21:56
By :
Mr'ก
ตั้งกระทู้ใหม่ครับ
Date :
2012-06-13 20:42:53
By :
mr.win
เปิดการใช้งาน extension obdc ใน php.ini รึยังครับ?
ประวัติการแก้ไข 2012-06-14 09:07:36
Date :
2012-06-14 09:07:05
By :
nonnyohiyo
Load balance : Server 05